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

Manfred Schubert dev at schubert-it.com
Wed Nov 2 12:32:23 CDT 2016

Am 01.11.2016 um 21:43 schrieb Michael Ilseman <milseman at apple.com>:
> 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.

So is „binding memory to a type“ like declaring the intent to the compiler that this memory is accessed as a certain type?

> [1] https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#memory-model-explanation

Re-reading this, I guess I don’t even understand the need for memory being initialized and deinitialized. I understand that it is useful to have a defined initial value, but why is that a requirement for raw memory? If I receive raw memory from outside of Swift, would this already be „bound“ and „initialized“? Many raw data can be interpreted in multiple ways, so it cannot be bound to any particular type, but it is initialized with meaningful data already.
And what does deinitialize actually do? How could a row of Ints be deinitialized for example? Or is it zeroing the raw bytes of the memory?


More information about the swift-users mailing list