5

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?

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
  • See: http://stackoverflow.com/questions/324053/find-out-the-size-of-a-net-object – Jon B Mar 10 '09 at 19:13
  • Jon B: That question is about the size of any object in .NET while this question is about the size of instances of the .NET Object class. A totally different question. – Tamas Czinege Mar 10 '09 at 19:20

2 Answers2

5

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
  • 1,421,763
  • 867
  • 9,128
  • 9,194
1

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.