You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #7773 there are proposals to control a type's alignment, but there is still no way to query it. Therefore, I suggest the addition of alignof and instance_alignof, which are usable wherever sizeof and instance_sizeof also are:
@[Align(instance_alignof(Bar))]
buf = uninitialized UInt8[instance_sizeof(Bar)]
bar = buf.to_unsafe.as(Bar)
Also this would provide a means to implement type-aware allocators in native Crystal that align their pointers correctly. The benefits may not be immediately apparent as nothing could have a larger alignment than Int128 (16 bytes) right now, but this could change if eventually #3057 arrives.
The alignment for a single instance variable of a type can be implemented as alignof(Foo, @z). Normally this is identical to alignof(typeof((x = uninitialized Foo; x.@z))), but a separate syntax is necessary because #7773 also allows @[Align] to be applied to an individual instance variable.
The text was updated successfully, but these errors were encountered:
In #7773 there are proposals to control a type's alignment, but there is still no way to query it. Therefore, I suggest the addition of
alignof
andinstance_alignof
, which are usable whereversizeof
andinstance_sizeof
also are:It would become possible to write things like:
Also this would provide a means to implement type-aware allocators in native Crystal that align their pointers correctly. The benefits may not be immediately apparent as nothing could have a larger alignment than
Int128
(16 bytes) right now, but this could change if eventually #3057 arrives.The alignment for a single instance variable of a type can be implemented as
alignof(Foo, @z)
. Normally this is identical toalignof(typeof((x = uninitialized Foo; x.@z)))
, but a separate syntax is necessary because #7773 also allows@[Align]
to be applied to an individual instance variable.The text was updated successfully, but these errors were encountered: