Skip to content

Instantly share code, notes, and snippets.

@finestructure
Last active June 20, 2016 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finestructure/5ecc4c3d2ff85ea1ed17dcaf078795ea to your computer and use it in GitHub Desktop.
Save finestructure/5ecc4c3d2ff85ea1ed17dcaf078795ea to your computer and use it in GitHub Desktop.
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