views:

380

answers:

2
+4  Q: 

.NET Object size

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
argh, yea. thanks
+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
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
That tag didn't last long. ;-)
John MacIntyre
figured. Thought I'd try. :)
Michael Meadows