0

If I have:

int[] d = {1,2,3};

which is the exact allocated space in memory of the array object referenced by d?

Is it only 3 * 4 = 12 byte or there are other bytes like in Java (i.e. object header, padding, and so on)?

P.S. I noticed that I can't use sizeof operator...

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
xdevel2000
  • 20,780
  • 41
  • 129
  • 196
  • 1
    What exactly are you trying to do? Memory measurement in managed languages is more complex like unmanaged ones like c#, so `sizeof` is not as straight-forward an operation. – D Stanley Dec 07 '15 at 14:13
  • 4
    Have a look here: [http://stackoverflow.com/questions/1589669/overhead-of-a-net-array](http://stackoverflow.com/questions/1589669/overhead-of-a-net-array) It shows hat the overhead for a reference type array is 16 bytes wheras the overhead for a value type array is 12 bytes. – Sebastian Schumann Dec 07 '15 at 14:13
  • Yes, there are more bytes also allocated. Where did you get the idea of `sizeof`? This is not C++. This is completely different language. Actually, you can do something like sizeof with [Marshal.SizeOf](https://msdn.microsoft.com/library/5s4920fa(v=vs.100).aspx) – quetzalcoatl Dec 07 '15 at 14:14
  • Have another look here: http://stackoverflow.com/questions/207592/getting-the-size-of-a-field-in-bytes-with-c-sharp#207605 – Tamas Ionut Dec 07 '15 at 14:14

0 Answers0