Skip to content

Quick Question: Do inline arrays require intra-index padding? #111918

Answered by jilles-sg
toupswork asked this question in Q&A
Discussion options

You must be logged in to vote

The elements of regular arrays, inline arrays and stackalloc can be described by the same Span<T>, so if the layout of the elements differed between those three cases it would be really expensive. As implemented in .NET, access to a span does not care what the span was created from.

As for uses of inline arrays, they could be used as a replacement for stackalloc that also allows managed types and more generally if a fixed number of elements is needed (which may not be particularly common). However, exposing an inline array as such in a public API seems unwise because of its weird conversion to span. Also, they interact poorly with collections (IEnumerable<T>, etc.) and async code.

If an i…

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@toupswork
Comment options

Answer selected by toupswork
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants