[swift-users] What is "binding" memory?

Andrew Trick atrick at apple.com
Tue Nov 1 15:40:02 CDT 2016

> On Nov 1, 2016, at 11:55 AM, Manfred Schubert via swift-users <swift-users at swift.org> wrote:
> The "UnsafeRawPointer Migration" guide talks about "binding memory to a type“ as if that was a well known term. I have never heard of it yet though, and googling it returns no relevant results. I do not understand what binding memory is supposed to do.
> The migration guide says "Binding uninitialized memory to a type prepares the memory to store values of that type“, but clearly raw memory does not need to be prepared (and cannot be) to hold any arbitrary type and value.
> So what is this for, what does it actually do, and to whom is it done (the raw pointer, or the typed pointer which is returned, or the raw memory)?
> Manfred

Hi Manfred,

At the top of the migration guide is a link to the memory model explanation:

"A memory location's bound type is an abstract, dynamic property of the memory used to formalize type safety.”

I’m not sure I like the “prepares the memory” language myself. Binding memory communicates to the compiler that the memory locations are safe for typed access. Nothing happens at runtime--until someone writes a type safety sanitizer. It affects the abstract state of the memory location, independent of the pointer variable used to access that memory. Binding memory returns a typed pointer for convenience and clarity, but there’s nothing special about that particular pointer value.

Initialized memory is always bound to some type. A rawpointer can be used to access that memory without knowing its bound type.


More information about the swift-users mailing list