<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. 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=""> </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=""> 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=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UInt8</span><span style="font-variant-ligatures: no-common-ligatures" class="">>) </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=""> 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=""> }</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=""> 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. 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?</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>