[swift-users] Data(bytesNoCopy:count:deallocator)

Stéphane Lizeray stephane at lizeray.net
Tue Aug 23 10:40:17 CDT 2016


Hello,

I create an UsafeMutableRawPointer using the allocate method.

Later on I want to create a Data struct from this pointer using the bytesNoCopy initializer. Which deallocator should I pass?

It looks like this:

let retPointer = UnsafeMutableRawPointer.allocate(bytes: size, alignedTo: MemoryLayout<UInt8>.alignment)
….

let d = Data(bytesNoCopy: retPointer, count: size,deallocator:Deallocator.free)

Thanks,

Stéphane

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160823/c7c74b7c/attachment.html>


More information about the swift-users mailing list