Why is a 1 character .NET string 32 bytes in x64? -
i've been trying figure out overhead of string in .net 4 x64. i've got far.
- 16 byte object header x64
- 4 bytes stringlength field (arraylength gone in .net 4)
- (length + 1) * 2 bytes string content (utf-16, null terminated)
so you'd expect 1 character string 16 + 4 + 4 = 24 bytes. it's divisible 8 shouldn't need padding.
but when @ sizes in windbg see them taking 32 bytes. when !dumpobject
them size 28 bytes, assume getting rounded 32. what's going on? there round of memory alignment happening?
i suspect first character aligned on 8-byte boundary on x64, when passed pointer unmanaged code, it's properly-aligned pointer. figures fit in the ones got measuring string size recently, leading formulae of:
32 bit: 14 + length * 2 (rounded 4 bytes) 64 bit: 26 + length * 2 (rounded 8 bytes)
so in 64 bit clr, 0-length string takes 32 bytes reckoning.
Comments
Post a Comment