<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">I am writing a tutorial and creating a wrapper on streaming compression. &nbsp;In the code, I setup the stream source pointer: (input is of type Data)</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures" class="">// set up the stream with the input source</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; input.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">withUnsafeBytes</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { (bytes: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UnsafePointer</span><span style="font-variant-ligatures: no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UInt8</span><span style="font-variant-ligatures: no-common-ligatures" class="">&gt;) </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; stream.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">src_ptr</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = bytes</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; }</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="font-family: Helvetica; font-size: 12px;" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; stream.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">src_size</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = input.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">count</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class=""><br class=""></span></div></div><div style="font-family: Helvetica; font-size: 12px;" class="">Input is guaranteed to be alive for the entire lifetime of the stream. &nbsp;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. &nbsp;Anyone know if I'm I dipping into undefined behavior here?</div><div style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px;" class="">Thanks in advanced,</div><div style="font-family: Helvetica; font-size: 12px;" class="">Ray</div><div class=""><br class=""></div></div></body></html>