Skip to content

Alignment of first element in managed byte array #98863

Answered by EgorBo
tmds asked this question in Q&A
Discussion options

You must be logged in to vote

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 find it in https://github.com/dotnet/runtime/blob/main/docs/design/specs/Memory-model.md.

I don't think object layout should be mentioned there anyhow. E.g. String doesn't promise pointer alignment for chars.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@tmds
Comment options

tmds Feb 23, 2024
Collaborator Author

@EgorBo
Comment options

EgorBo Feb 23, 2024
Collaborator

@tmds
Comment options

tmds Feb 23, 2024
Collaborator Author

@VSadov
Comment options

VSadov Feb 23, 2024
Collaborator

Answer selected by tmds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants