It seems to me that this initializer is not following the documentation of withUnsafeBytes which says not to use the pointer outside the passed closure. What's the reason for writing the init like this? Of course, in absence of a comment, I don't know of its specific use case.
AFAIK Data doesn't guarantee using contiguous memory. What are the implications of that here?
Do you happen to know why the pointer shouldn't be accessed outside the closure?
public init(data : Data, cache : FBReaderCache? = FBReaderCache()) {
self.count = data.count
self.cache = cache
var pointer : UnsafePointer<UInt8>! = nil
data.withUnsafeBytes { (u8Ptr: UnsafePointer<UInt8>) in
pointer = u8Ptr
}
self.buffer = UnsafeRawPointer(pointer)
}
It seems to me that this initializer is not following the documentation of
withUnsafeByteswhich says not to use the pointer outside the passed closure. What's the reason for writing the init like this? Of course, in absence of a comment, I don't know of its specific use case.AFAIK
Datadoesn't guarantee using contiguous memory. What are the implications of that here?Do you happen to know why the pointer shouldn't be accessed outside the closure?