What is the size of a heap-allocated Object in .net, including management overhead? I'm assuming Objects are allocated along 4-byte boundaries, or is a different approach used?
A:
Depends on a machine, on 32 bit machine it is usually 4-bytes. However, on 64 bit box, it is 8-bytes, and so on.
I think you're talking about the size of a *reference* rather than the object overhead itself.
Jon Skeet
2009-03-10 19:15:21
argh, yea. thanks
2009-03-10 19:16:11
+4
A:
4 byte boundaries on x86. Possibly 8 byte boundaries on x64.
There's an 8 byte overhead on x86, for a type reference and a sync block. I wouldn't be surprised to find that's 12 or 16 bytes on x64.
For some reason, on x86 an instance of just System.Object
appears to take 12 bytes, making 12 bytes the absolute minimum size possible - but a class with an int
also takes 12 bytes. I've no idea why this is the case.
Jon Skeet
2009-03-10 19:14:03
You shouldn't be able to answer the high AND low level questions so well. I'm retaging with a new tag: stump-the-skeet.In this case, this question is the stump-the-skeet:fail.
Michael Meadows
2009-03-10 19:19:51