heap - .NET CLR: How does runtime calculate size of object? -


there large object heap in .net objects size more 85kb. understand size of object in heap calculated this

  1. size of properties , fields of primitive types , instances of value types (because stored inside parent instance)
  2. size of references other instances of classes (because stored separately).

examples:

  1. 10 objects of reference type (each 10kb) , 1 object of reference type contains of them => objects should not put loh
  2. 2 objects of reference type (each 86kb) , object of reference type contains of them => 2 objects in loh last 1 in usual heap

is correct calculation schema? examples correct?

the allocation cost of reference type in clr comprised of fixed overhead (dependent on architecture) plus total amount of members (all values, references, 4-byte or 8-byte).

refer to: what memory overhead of .net object

it not allocate memory space of referred object, reference value.

if allocate 10kb object, won't hit loh.

if allocate array of 10 x 10kb classes, neither list nor objects in loh. list in fact array of 10 x size of reference architecture.

if class struct, list include memory space required house 10kb struct, 10 times, in theory plonk list (and virtue of value-types, objects too) on loh.

don't forget, list<t> allocates space based on algorithm (currently, x*2). isn't put in list takes space, how capacity list has.

the loh allocation limit implementation detail of runtime , potentially change. it's interesting see how works, don't build relies on how currently works.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -