Last active
March 27, 2021 07:55
-
-
Save LucianoPAlmeida/94257311e7715951171d402a628667d9 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