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

Rien Rien at Balancingrock.nl
Fri Nov 4 02:26:52 CDT 2016


> On 03 Nov 2016, at 23:58, Manfred Schubert via swift-users <swift-users at swift.org> wrote:
> 
> Am 03.11.2016 um 15:41 schrieb Rien <Rien at Balancingrock.nl>:
>> 
>> Ah, but that is not the case.
>> 
>> It is important to differentiate between the “gateway” to the memory and the memory area itself.
>> Different programming languages/compilers have different approaches, but I believe that Swift allocates a struct for every gateway.
>> widePtr and narrowPtr are two different gateways. They refer to different struct's. But the struct for each of them refers to the same memory area.
> 
> When you have a look at the Swift memory model explanation
> 
> https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#memory-model-explanation
> 
> it looks like memory can only be bound to one type at a time. In particular in the third example where a pointer of type T is used to initialize memory which is bound to type U, it says that the behavior is undefined.
> 
> There is also withMemoryRebound(to:capacity:) which binds memory to another type, executes the code that accesses the memory as this type in a closure, and the restores the old type binding.
> 
> That makes me think that it is not allowed to have multiple „gateways“ to the same memory area at the same time.
> 

It only means that memory access must be typed, not existence.

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

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http://github.com/Swiftrien
Project: http://swiftfire.nl






More information about the swift-users mailing list