I have the following class:
public class MyClass
{
public string Name { get; set; }
public int Age { get; set; }
public double Amount { get; set; }
}
When I try to find out size of this class on a 64 bit system by using WinDbg I get the size 40 which I am not able to understand, as far as I have read MyClass should have
8 bytes for SyncBlock
8 bytes for TypeHandle
8 bytes for string reference
4 bytes for Int32
8 bytes for double
= 36 bytes
I don't have 10 reputation that's why i am not able to post image. Anyone has any idea why WinDbg is showing 4 extra bytes ?
I believe what you're seeing is the effect of things needing to align to 8 byte boundaries in 64 bit builds (and 4 byte boundaries in 32 bit builds). 40 is the closest size >= 36 that is on an 8 byte boundary. These links talk about object size:
Of Memory and strings (Jon Skeet's blog)
Benchmarking C# Struct and Object Sizes
Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects
How Much Memory Does a C# String Take Up
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With