0

Possible Duplicate:
How to get object size in memory?

I would like to get the size of an object of unknown type, I think about sizeof but it is used only for concrete data types, i.e sizeof(char); and also about Marshal.Sizeof(object) but this informs that the size returned is not true because the object is marshaled before its size is calculated.

Community
  • 1
  • 1
PointedC
  • 101
  • 8
  • 1
    Basically, there is no way to calculate the object's in-memory size. http://stackoverflow.com/questions/605621/how-to-get-object-size-in-memory has a good collection of links – Zruty Nov 18 '11 at 15:53
  • 1
    Why exactly do you want to know this? This either makes no sense or there are different methods / answers depending on what you are going to use this information for – Justin Nov 18 '11 at 15:56
  • 5
    There simply is no way to discover the true size of a managed object. Feature, not a bug. – Hans Passant Nov 18 '11 at 15:56

1 Answers1

0

If I had a bottle of unknown volume and it was half full could you tell me how much water was in it?

You could just wonder what the definion "bottle" is, or in this case , what is an unknown object? Is it expressable in a memory size at all? No idea. But to answer the question. No.

Mnescat
  • 195
  • 1
  • 13