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

Michael Ilseman milseman at apple.com
Tue Nov 1 15:43:22 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)?

This is more so a semantic distinction rather than some kind of physical operation. The memory is not altered, but all reads and writes to that memory location have to be through the “bound type”. If it’s “bound” to some type T, you must only read and write through values of type T, and not some unrelated type. This is in order to honor Swift's memory model while still exposing access to raw memory (see [1]), and to do so one must be careful about how they treat that memory so as to not violate “strict aliasing” (see [2]). This is similar to the notion of strict aliasing in C (see [3]). 

[1] https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#memory-model-explanation <https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#memory-model-explanation>
[2] https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#strict-aliasing
[3] http://blog.regehr.org/archives/1307

> Manfred
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161101/a04aef60/attachment.html>

More information about the swift-users mailing list