Last active
June 20, 2016 06:49
-
-
Save finestructure/5ecc4c3d2ff85ea1ed17dcaf078795ea to your computer and use it in GitHub Desktop.
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
public final class SmartPointer<T> { | |
public let pointer: UnsafeMutablePointer<T> | |
private let destructor: (UnsafeMutablePointer<T>) -> Void | |
public init(pointer: UnsafeMutablePointer<T>, destructor: (UnsafeMutablePointer<T>) -> Void) { | |
self.pointer = pointer | |
self.destructor = destructor | |
} | |
deinit { | |
self.destructor(self.pointer) | |
} | |
} | |
let smartPrt = SmartPointer(pointer: UnsafeMutablePointer<Int>(malloc(1024))!, destructor: free) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment