[swift-users] Extracting arbitrary types (e.g. UInt16) out of Data

Joe Groff jgroff at apple.com
Mon Jun 26 12:58:46 CDT 2017

> On Jun 26, 2017, at 10:20 AM, Charles Srstka via swift-users <swift-users at swift.org> wrote:
> Rats, I was hoping that one of the reasons about being so explicit what we’re going to access and where with bindMemory() and friends would be to take care of these sorts of issues.

There are restrictions that unfortunately prevent unaligned memory support from being the pervasive default; particularly, we want typed pointers to be able to "toll-free-bridge" with typed C pointers, and C also requires well-alignedness of typed memory accesses. Swift's runtime generics model also means that unspecialized code would be using value witness functions to load/store values from memory, and the value witness functions are compiled to assume alignment of their arguments. It would be reasonable for us to add load/storeUnaligned APIs to the RawPointer types that explicitly did unaligned operations; these would however have to be restricted to working only on trivial types that don't require reference counting.


More information about the swift-users mailing list