How to get the size of managed class?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to know the size, in bytes, of System.Drawing.Color.

In general; how to get the size of managed object of class instance and of
class type?
 
HI
Sharon said:
I need to know the size, in bytes, of System.Drawing.Color.

In general; how to get the size of managed object of class instance and of
class type?

Why you need to know that?

Remember that an instance of a class is not an one block of memory, it has
references to another instances that live in a separate space.
 
I need to know the size, in bytes, of System.Drawing.Color.

Color is basically defined like this

[StructLayout(LayoutKind.Explicit)]
struct Color
{
[FieldOffset(0)] long value;
[FieldOffset(8)] short knownColor;
[FieldOffset(10)] short state;
[FieldOffset(12)] string name;
}

So it should be 16 bytes on 32-bit systems, 20 bytes on 64-bit.


Mattias
 
Mattias Sjögren said:
I need to know the size, in bytes, of System.Drawing.Color.

Color is basically defined like this

[StructLayout(LayoutKind.Explicit)]
struct Color
{
[FieldOffset(0)] long value;
[FieldOffset(8)] short knownColor;
[FieldOffset(10)] short state;
[FieldOffset(12)] string name;
}

So it should be 16 bytes on 32-bit systems, 20 bytes on 64-bit.

Mattias,

Above is how it was defined in v1.x, but as this explicit layout was not valid on 64 bit, it
was changed into a sequential layout.

Willy.
 
Above is how it was defined in v1.x, but as this explicit layout was not valid on 64 bit, it
was changed into a sequential layout.

Good point Willy, I only checked the first version I found.

But that doesn't change the sizes I posted, does it?


Mattias
 
Mattias Sjögren said:
Good point Willy, I only checked the first version I found.

But that doesn't change the sizes I posted, does it?
Mattias ,

No, the sizes are correct, just the structure layout is different

32 bit:
long
string (ref 4 bytes))
short
short

64 bit.
string (ref 8 bytes)
long
short
short

Willy.
 
Back
Top