我正在实现一个纯粹的Swift NSData替代品.下面是我的Swift 2代码的一部分.据我所知,Data实例deinitialization没有destroy()和缓冲区指向的dealloc()字节block.那么,还有没有调用的任何方式destroy和dealloc()以防止内存泄漏之前对缓冲器指针的Data实例deinitializes?
public struct Data: DataContainer {
public typealias Block = UInt8
public var blocks: UnsafeMutableBufferPointer<Block>
public init(bytes: UnsafeMutablePointer<Block>, length: Int) {
// copy bytes
let bytesCopy = UnsafeMutablePointer<Block>.alloc(length)
bytesCopy.initializeFrom(bytes, count: length)
// init byte blocks
self.blocks = UnsafeMutableBufferPointer<Block>(start: bytesCopy, count: length)
}
}
Run Code Online (Sandbox Code Playgroud)