The tough .net question

I want to share a question that I'm confused about. Please check.: -)

How many GC threads do we have in a .NET process running on a quad-core i7 Process?

I said 4x2 = 8?

Which generation of GC uses more memory and why?

I told Gen2, but I don’t know why? I guessed because the size is displayed larger in each book or network. :-P

Is contravariance a consequence of covariance? Explain.

Its from generics but don't know how to explain it.

EnlistDistributedTransaction method not supported by any database?

Did I say Oracle and IBM DB?

The value of a CodeBase element in C # and where is it used?

I told the Assembly, but I don’t know the exact importance.

Well, I managed to clear the interview, but this question really brought me out. See if you can give me advice on these issues?

thanks Ajitpal

+4
source share
3 answers

covariance / contravariance

For CoVariance / ContraVariance, they may have thought of an example of arrays (or generally for RVW CoVariant objects)

class A { } class B : A { } static void Func(A[] a) { a[0] = new A(); } B[] b = new B[5]; Func(b); 

This is “legal” for the record, but it will use the assignment (in Func) (ArrayTypeMismatchException). Here the covariator caused a problem. From POV Func, this is "weird." I will say that the ContraVariance is the “missing” consequence of the ReadWrite CoVariance (it should be there, but obviously this cannot be done)

For gc

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

He sees that the GC of the workstation always happens in the thread that allocates memory, so there is no "extra" thread for the GC. I will add that this is version dependent, so it can vary from version to .NET version (and Mono does it differently). With Server GC, you have dedicated threads for the GC, one for each processor. The I7 square in the example probably has HT (HyperThreading), so there are 8 "cores", therefore 8 threads.

Generation Size

For the size of generations ... I would say that "usually" Gen2 is larger because large objects are always Gen2 ( http://msdn.microsoft.com/en-us/magazine/cc534993.aspx ) (technically they are not Gen2. .. They live in a separate space, which is checked during the Gen2 check, but we will ignore it ... the question was not very clear and it is determined by the implementation and are opaque enough that we don’t know EXACTLY how Gens "LinkedListed" in memory), and long-lived objects will go into Gen2 (therefore, after the phase of the "launch" of your program, single and other long-lived objects are all in Gen2)

BUT ... In general, this is not so.

Let's say you create a program that performs a single selection ( var obj = new object() ). This distribution will start with Gen0. When this object is selected, there is one object, and this object is Gen0, so technically Gen0 is the largest.

DTC

IBM DB2 supports DTC, and therefore Oracle:

This is semi-tagological, but I would say that EnlistDistributedTransaction is not supported

  • DBs that do not support transactions (some MySql, depending on the type of DB database)
  • which the transaction coordinator / transaction coordinator does not support, but from what I read, the newer MySql, using a base database that supports transactions, seems to be able to support DTC (for example, read http://dev.mysql.com/doc/refman /5.0/en/xa.html )

<CodeBase> Element

Wrote THIS way much more clearly

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

You can force the application to work with a specific version of the referenced assembly. Useful if there is a “gap of changes” between build versions.

+3
source
  • Detail implementation. May vary in different versions of .net. And may differ between the GC server / client. And it may change depending on what stage the GC is at. I assume there will be as many threads as there are (virtual) processors / cores, at least in some gc phases, so a 2x hyper-stream ATV can use up to 8 threads. But I would not be surprised if some of the steps are simply monotonous.
    In particular, the client GC works mostly in parallel with your other code. Therefore, using all cores may be a bad idea, because it slows down the program. The GC server, on the other hand, is optimized for maximum speed and stops the entire program. So for a multi-threaded server, the GC GC sounds like a good idea.

  • Most likely, Gen2, because all long-lived objects accumulate there. But it depends on your memory allocation scheme. Other generations have (soft) memory limits, after which collection for this generation occurs.
    And then there is a bunch of large objects, which is a bunch separated from ordinary heaps. If you select large objects, there is a good chance that it will become more than ordinary generation heaps. I think that it was assembled only during the collections of Gen2, so it can be considered part of Gen2.

0
source

Covariance and contravariance mainly relate to the ability to use a less derived type than the original specified type.

Covariance . To use a more derived type than indicated in the original.

Contravariance . To use a more general type (i.e., less derivative) than originally specified.

For more information, visit the article below https://docs.microsoft.com/en-us/dotnet/standard/generics/covariance-and-contravariance

0
source

Source: https://habr.com/ru/post/1344234/


All Articles