Skip to content

How can I get the size of a type? #29

Discussion options

You must be logged in to vote

Crossposting answer from @Azoy:

If you can, you can use MemoryLayout<Type>.size, but if all you have is the metadata (or a generic Any.Type) you can get the type's size from metadata.vwt.size. Keep in mind though, that for tuples you could have something like: (Int8, Int, Int8) and currently the compiler emits padding for the first byte integer, so simply iterating the raw value by its element type size might not always work.

Replies: 1 comment 1 reply

Comment options

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

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