What does large
actually mean in the context of structs and in
parameter modifier?
#91207
-
I see that Span itself contains two fields: reference and length. So, its size is obviously larger than the size of the reference. And yet designers did not think applying Is there an objective criterion for the size of readonly struct when using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It depends on several bits of context. This includes, but isn't limited to:
Some platforms allow structs that are less than or equal to 2 pointers in length to be passed in multiple registers. All of this nuance basically means there is no "correct" answer and context has to be taken into account. A good general rule of thumb for perf oriented code is that anything that is 16-bytes or less should be passed by value, if it's more than that consider using The Framework Design Guidelines essentially outlines that structs should:
There's then some annotations from different team members discussing some of the points I gave above. Of course, internal or domain specific types can break these guidelines; but they do layout some solid foundations around when/why structs should or should not be used. Structs that are too large or have a layout that doesn't allow them to be passed in register for a given platform are ultimately still passed by reference. The difference between So ultimately it really depends and requires you to profile, measure, and consider the contract for the type and how its intended to be used. Both at the current point in time and in the theoretical future for any changes that might happen. |
Beta Was this translation helpful? Give feedback.
It depends on several bits of context. This includes, but isn't limited to:
Some platforms allow structs that are less than or equal to 2 pointers in length to be passed in multiple registers.
Some platforms allow structs that contain 1-4 floating-point or 1-4 SIMD types to be passed in multiple registers.
Some platforms allow structs with many fields that are less than or equal to a pointer in length to be passed in a single register.
All of this nuance basically means there is no "correct" answer and context has to be tak…