Created
November 3, 2016 12:06
-
-
Save sbooth/ee86d52e03a5cfa42d725dbcb183a465 to your computer and use it in GitHub Desktop.
Test the behavior of UnsafeMutablePointer.initialize(to:)
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 | |
class Test { | |
init() { | |
print("init") | |
} | |
deinit { | |
print("deinit") | |
} | |
} | |
func make_ptr(_ test: Test) -> UnsafeMutablePointer<Test> { | |
let test_ptr = UnsafeMutablePointer<Test>.allocate(capacity: 1) | |
test_ptr.initialize(to: test) | |
return test_ptr | |
} | |
func delete_ptr(_ test_ptr: UnsafeMutablePointer<Test>) { | |
test_ptr.deinitialize() | |
test_ptr.deallocate(capacity: 1) | |
} | |
let test_ptr = make_ptr(Test()) | |
delete_ptr(test_ptr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment