C # How to find the reference type size

I was wondering if there is a way to find the size of the reference type in C #. I did a few googling, and the general idea on the forums seems like this is impossible. I thought I would ask you guys and see if anyone here knows better.

After all, should profiling tools have a way to do this? I know that it is usually not necessary to know this information, but it would be useful to have in some situations.

+3
source share
3 answers

Check this detailed answer from Jon, you will find useful information.

+1
source

, profilig. JIT , , , ( 32 64 ), (MS, Mono, GNU.NET ..), .

:

  • 32bit 64bit

  • ( VTable ..), , ( ), , ( , , ).

, , , (, , , , .. )?

0

Hmmm. I would use a profiling tool, but I think something like this might work:

long before = System.GC.GetTotalMemory(true);
Foo instance = new Foo();
long after = System.GC.GetTotalMemory(true);
long consumed = after - before;
0
source

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


All Articles