-
-
Save artem-shmatkov/d56d19c30bf870724ebeaea1a5b9b5ee to your computer and use it in GitHub Desktop.
Copy-on-Write
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func print(address o: UnsafeRawPointer ) { | |
print(String(format: "%p", Int(bitPattern: o))) | |
} | |
var array1: [Int] = [0, 1, 2, 3] | |
var array2 = array1 | |
//Print with just assign | |
print(address: array1) //0x600000078de0 | |
print(address: array2) //0x600000078de0 | |
//Let's mutate array2 to see what's | |
array2.append(4) | |
print(address: array2) //0x6000000aa100 | |
//Output | |
//0x600000078de0 array1 address | |
//0x600000078de0 array2 address before mutation | |
//0x6000000aa100 array2 address after mutation | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment