> On Nov 1, 2016, at 11:55 AM, Manfred Schubert via swift-users 
> <swift-users@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:
https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#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.

-Andy
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to