-
What's the alignment of the first element in a managed byte array? Is it guaranteed to match the machine word size, for example: 8 bytes aligned on x64, and 4 bytes on aligned on x86? I don't find it in https://github.com/dotnet/runtime/blob/main/docs/design/specs/Memory-model.md. So maybe no alignment may be assumed? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Arrays are GC objects, so they're pointer-aligned (e.g. 8 bytes on 64bit). Array's data is located at
I don't think object layout should be mentioned there anyhow. E.g. String doesn't promise pointer alignment for chars. |
Beta Was this translation helpful? Give feedback.
Arrays are GC objects, so they're pointer-aligned (e.g. 8 bytes on 64bit). Array's data is located at
sizeof(void*) + 4 bytes + 4 bytes
in CLR,so the answer is: yes, first item in arrays is always pointer-aligned in CLR (might not be true in other implementations).
The only exception are arrays of
double
(and long?) on 32bit which get special treatment to promise 8 byte alignment on 32 bit platforms.I don't think object layout should be mentioned there anyhow. E.g. String doesn't promise pointer alignment for chars.