[swift-users] Getting at the bytes of Data

Ray Fix rayfix at gmail.com
Fri Dec 9 10:39:02 CST 2016


I am writing a tutorial and creating a wrapper on streaming compression.  In the code, I setup the stream source pointer: (input is of type Data)

  // set up the stream with the input source
  input.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) in
    stream.src_ptr = bytes
  }
  stream.src_size = input.count

Input is guaranteed to be alive for the entire lifetime of the stream.  Everything seems to work fine but I thought I remember reading somewhere that it is bad form to let the bytes escape out of the withUnsafeBytes closure.  Anyone know if I'm I dipping into undefined behavior here?

Thanks in advanced,
Ray

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


More information about the swift-users mailing list