It's largely about semantic, the memory layout for simple types should be pretty solid by now.
I'm more concerned about memory binding. In an ideal world, each part of the memory would be tagged, as Int
or UInt8
, and we're trying to read Int
out of UInt8
memory, which is not allowed in Swift. (There's also an implication that using memory with incorrect binding could lead to undefined behavior though I'm not sure how that works.)
assumingMemoryBound
, well, assumes that you already bind that region of memory to Int
at some point (which we didn't) and binding memory to a type would cause it to lose binding of the previous type (we would lose UInt8
binding) so we don't want that either.
So I'm trying to find a variant that doesn't change/assume the binding of the memory, and load(fromByteOffset:as:)
seems to be what I want.
If you're curious, the docs as well as SE-0107 would be useful.