[vm/ffi] add alignmentOf<T> (besides just having sizeOf<T>) #39964
Labels
area-vm
Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
library-ffi
Allocation in
package:ffi
currently only relies on thesizeOf
an FFI type. However, when allocating more thancount: 1
, it should also take into account the required alignment.For example, the size of of a struct might be 28 bytes, while the required alignment should be 8 bytes. This means that when allocating
count: 2
, the second value should be at an offset of 32 bytes, rather than 28 bytes.Proposed Solution
Add the
alignmentOf<T>
:Note that we might want to remove the generic use of
sizeOf<T>
(#38721 (comment)), the same would be true foralignmentOfT<T>
.Original Example
I don't understand why
sizeOf<KeyboardInput>()
gives me size of 32 instead of 28 (but withpadding
field removed it correctly says 24).Originally posted by @marad in #37271 (comment)
Thanks for reporting this @marad.
cc @mkustermann
The text was updated successfully, but these errors were encountered: