[swift-users] Getting at the bytes of Data

Ray Fix rayfix at gmail.com
Fri Dec 9 11:04:47 CST 2016

Hi Philippe,

Thank you for your response!

> On Dec 9, 2016, at 8:44 AM, Philippe Hausler <phausler at apple.com> wrote:
> So letting the bytes escape from the closure could potentially be in that territory of “bad things may happen”. If you know for certain that the Data will not be mutated and it’s underlying storage will last for the duration of the usage then you should be able to get away with it.

So far it is looking like I am getting away with it. I believe the conditions that you state hold.

> The bytes pointer is an inner pointer return from the encapsulating object backing the struct Data. Since that backing object can potentially be deallocated via mutation or the buffer may be reallocated (which very often can cause the base address of the pointer to change) we decided it would be safer to use a closure to ensure the lifespan of the bytes over the access to the bytes.
> Perhaps it might be best to understand more of what you are trying to do to offer a better solution.

I am trying to use the compression_stream C API in the Compression framework and wrap it so it is a bit more Swifty.  :]

A full gist of the playground is here: https://gist.github.com/rayfix/a286bb55accffef09249ba3535993782 <https://gist.github.com/rayfix/a286bb55accffef09249ba3535993782>

See line 91.

Appreciate the hints. 

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

More information about the swift-users mailing list