简体   繁体   English

硬.net问题

[英]Hard .net Question

I want to share some question in which i got confused. 我想分享一些我感到困惑的问题。 Please check. 请检查。 :-) :-)

How many GC threads do we have in a .NET process running on quad-core i7 Process? 在四核i7进程上运行的.NET进程中有多少个GC线程?

I said 4x2=8? 我说4x2 = 8?

Which GC generation utilize more memory and why? 哪一代GC使用更多内存?为什么?

I said Gen2 , but don't know why? 我说Gen2,但不知道为什么? i guessed because it's size is shown bigger in every book or net. 我猜对了,因为它的尺寸在每本书或网中都显得更大。 :-P :-P

Contravariance is the corollary of covariance? 逆变是协方差的必然结果? Explain. 说明。

Its from generics, but don't know how to explain it. 它来自仿制药,但不知道如何解释它。

EnlistDistributedTransaction method is not supported by which database? EnlistDistributedTransaction方法不支持哪个数据库?

i said Oracle and IBM DB? 我说Oracle和IBM DB?

Importance of codeBase Element in C# and where it is use? codeBase元素在C#中的重要性和使用位置?

I said Assembly, but don't know the exact importance 我说大会,但不知道确切的重要性

Well , I managed to clear the interview, but these question really took me out. 好吧,我设法清除了面试,但这些问题真的把我带走了。 Please see if you can give me some advice on these question? 请看看你能否就这些问题给我一些建议?

thanks Ajitpal 谢谢Ajitpal

CoVariance/ContraVariance 协方差/逆变

For CoVariance/ContraVariance they were perhaps thinking of the example of Arrays (or in general of R/W CoVariant objects) 对于CoVariance / ContraVariance,他们可能会考虑数组的例子(或者一般是R / W CoVariant对象)

class A
{
}

class B : A
{
}

static void Func(A[] a) {
    a[0] = new A();
}

B[] b = new B[5];
Func(b);

This is "legal" to write, but it will throw on the assignment (in the Func) (ArrayTypeMismatchException). 这是写“合法”的,但它会抛出赋值(在Func中)(ArrayTypeMismatchException)。 Here the CoVariant caused a problem. CoVariant引起了一个问题。 From the POV of Func it's "strange". 从Func的POV来看,它是“奇怪的”。 I'll say that ContraVariance is a "missing" corollary of ReadWrite CoVariance (it should be there, but clearly it's impossible to do it) 我会说ContraVariance是ReadWrite CoVariance的“缺失”必然结果(它应该存在,但很明显它是不可能的)

For the GC 对于GC

http://architecturebyashwani.blogspot.com/2010/02/foreground-gc-and-background-gc.html http://architecturebyashwani.blogspot.com/2010/02/foreground-gc-and-background-gc.html

It SEEMS that Workstation GC always happens in the thread that allocates the memory, so there isn't any "extra" thread for the GC. 它看起来Workstation GC总是发生在分配内存的线程中,因此GC没有任何“额外”线程。 I'll add that this is version-dependant, so it could change from version to version of .NET (and Mono does it differently). 我将补充说,这是依赖于版本的,因此它可以从.NET的版本更改为版本(而Mono的版本也不同)。 With Server GC you have specialized threads for GC, one for each processor. 使用Server GC,您可以使用GC的专用线程,每个处理器一个。 The I7 Quad Core of the example probably has HT (HyperThreading), so 8 "cores", so 8 threads. 该示例的I7四核可能具有HT(超线程),因此有8个“核心”,因此有8个线程。

Generation Size 代大小

For the size of the generations... I would say that "normally" the Gen2 is larger, because large objects are always Gen2 ( http://msdn.microsoft.com/en-us/magazine/cc534993.aspx ) (technically they aren't Gen2... They live in a separate space that is checked when Gen2 is checked, but we will ignore this... the question wasn't very clear, and it is implementation-defined and opaque enough that we don't know EXACTLY how the Gens are "LinkedListed" in memory), and long lived objects will go to Gen2 (so after the "startup" phase of your program, the singletons and other long-lived objects are all in Gen2) 对于世代的大小...我会说“通常”Gen2更大,因为大对象总是Gen2( http://msdn.microsoft.com/en-us/magazine/cc534993.aspx )(技术上)它们不是Gen2 ......它们生活在一个单独的空间中,当Gen2被检查时会被检查,但我们会忽略这个......问题不是很清楚,而且它是实现定义的,不透明,我们不要我们确切地知道Gens在内存中是如何“LinkedListed”的,并且长寿命对象将转到Gen2(所以在程序的“启动”阶段之后,单例和其他长寿命对象都在Gen2中)

BUT ... in general this isn't true. 但是......总的来说这不是真的。

Let's say you make a program that does a single allocation ( var obj = new object() ). 假设您创建了一个执行单个分配的程序( var obj = new object() )。 That allocation will start at Gen0. 该分配将从Gen0开始。 When that object is allocated, there is a single object, and that object is Gen0, so technically Gen0 is the biggest one. 分配该对象时,只有一个对象,该对象为Gen0,因此技术上Gen0是最大的对象。

DTC DTC

IBM DB2 supports the DTC, and so Oracle: IBM DB2支持DTC,因此Oracle:

It's semi-tautological, but I would say that EnlistDistributedTransaction is not supported by 它是半重复的,但我会说不支持EnlistDistributedTransaction

  • DB that don't support transactions (some MySql, depending on the type of the base DB) 不支持事务的DB(一些MySql,取决于基本DB的类型)
  • DB that don't support a transaction monitor/transaction coordinator, but from what I've read, newer MySql, using base DB that support transactions, seems to be able to support DTC (for example read http://dev.mysql.com/doc/refman/5.0/en/xa.html ) 不支持事务监视器/事务协调器的数据库,但从我所读到的,较新的MySql,使用支持事务的基本数据库,似乎能够支持DTC(例如,读取http://dev.mysql。 com / doc / refman / 5.0 / en / xa.html

<codeBase> Element <codeBase>元素

Written THIS way it's much more clearer 这样写的方式更加清晰

http://msdn.microsoft.com/en-us/library/efs781xb.aspx http://msdn.microsoft.com/en-us/library/efs781xb.aspx

You can force your app to run with a particular version of a referenced assembly. 您可以强制您的应用程序与特定版本的引用程序集一起运行。 Useful if there are "breaking changes" between versions of an assembly. 如果程序集的版本之间存在“重大更改”,则非常有用。

Covariance and Contravariance basically deals with the ability how to use less derived type than original specified type. Covariance和Contravariance基本上处理如何使用比原始指定类型更少的派生类型的能力。

Covariance For use of more derived type than original specified. 协方差用于使用比原始指定更多的派生类型。

Contravariance For use of more generic type (ie Less Derived type) than originally specified. 逆变量用于使用比最初指定的更通用的类型(即Less Derived类型)。

For more clarification visit below article https://docs.microsoft.com/en-us/dotnet/standard/generics/covariance-and-contravariance 有关更多说明,请访问以下文章https://docs.microsoft.com/en-us/dotnet/standard/generics/covariance-and-contravariance

  1. Implementation detail. 实施细节。 Can differ in different versions of .net. 可以在.net的不同版本中有所不同。 And might differ between server/client GC. 并且服务器/客户端GC可能有所不同。 And might change depending on which phase the GC is in too. 并且可能会根据GC的相位而改变。 I assume it will be as many threads as there are (virtual) CPUs/Cores in at least some phases of the gc, so a 2x hyperthreaded quadocore might use up to 8 threads. 我假设它将在gc的至少某些阶段中存在与(虚拟)CPU /核心一样多的线程,因此2x超线程quadocore可能使用多达8个线程。 But I wouldn't be surprised if some phases are just singlethreaded. 但如果某些阶段只是单线程,我不会感到惊讶。
    In particular the client GC runs largely in parallel to your other code. 特别是客户端GC主要与您的其他代码并行运行。 So using all cores might be a bad idea because it slows the program down. 因此,使用所有核心可能是一个坏主意,因为它会降低程序的速度。 Server GC on the other hand is optimized for maximum speed and does stop the whole program. 另一方面,服务器GC针对最大速度进行了优化,并且可以停止整个程序。 So for Server GC multi-threading as much as possible sounds like a good idea. 所以对于Server GC多线程尽可能听起来是个好主意。

  2. Most likely Gen2 because all long lived objects accumulate there. 最有可能是Gen2,因为所有长寿命的物体都在那里积累。 But this depends on your memory allocation pattern. 但这取决于你的内存分配模式。 The other generations have (soft) memory limits after which a collection for this generation occurs. 其他代有(软)内存限制,之后会发生这一代的集合。
    And then there is the large object heap which is a heap separate from the normal generation heaps. 然后是大对象堆,它是与正常生成堆分开的堆。 If you allocate large objects there are good chances that it becomes bigger than the normal generation heaps. 如果你分配大型对象,它很可能会比正常的生成堆大。 I think it is only collected during Gen2 collections, so one could count it as part of Gen2. 我认为它只在Gen2集合中收集,因此可以将其视为Gen2的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM