<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Björn,<div><br></div><div><div>On Aug 7, 2012, at 8:24 AM, Björn Gustavsson wrote:</div><div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Mon, Aug 6, 2012 at 6:36 PM, Zabrane Mickael <<a href="mailto:zabrane3@gmail.com">zabrane3@gmail.com</a>> wrote:<br><blockquote type="cite">Hi guys,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I'm communicating with linked-in driver using the following code:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">control(Port, Command, Data) -><br></blockquote><blockquote type="cite"> case port_control(Port, Command, Data) of<br></blockquote><blockquote type="cite"> <<0, Result/binary>> -> Result; % <- LINE 468 handle a good case<br></blockquote><blockquote type="cite"> <<1, Error/binary>> -> {error, binary_to_term(Error)} % <- LINE 469 handle error case<br></blockquote><blockquote type="cite"> end.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">When compiling, I got this 02 warnings:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">$ make<br></blockquote><blockquote type="cite">Recompile: src/pimco.erl<br></blockquote><blockquote type="cite">src/pimco.erl:468: Warning: NOT OPTIMIZED: sub binary is used or returned<br></blockquote><blockquote type="cite">src/pimco.erl469: Warning: NOT OPTIMIZED: sub binary used by erlang:binary_to_term/1<br></blockquote><blockquote type="cite">make[2]: Nothing to be done for `all'.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Is there a way to get rid of these warnings and avoid a full binary copies?<br></blockquote><br>Yes, you can get rid of the warnings by *not* using the bin_opt_info compiler<br>option.<br></div></blockquote><div><br></div>;-)</div><div><br><blockquote type="cite"><div>No, there is nothing to avoid here. The warning says that<br>a sub binary is created. A sub binary is small term that<br>references a part of a binary. Sub binaries is usually an<br>efficient way to reference just a part of a binary.<br></div></blockquote></div><div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000"><br></font>So there is *no* copying of the binary data going on in<br>your example.<br></div></blockquote><div><br></div><div>Crystal clear.</div><div><br></div></div><div apple-content-edited="true">
<span class="Apple-style-span" style="orphans: 2; text-indent: 0px; widows: 2; -webkit-text-decorations-in-effect: none; "><div style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">This version is funny because the compiler now throws only one WARNING instead of two:</div><div style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">$ make</div><div style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">src/pimco.erl:492: Warning: NOT OPTIMIZED: sub binary is used or returned</div><div style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><br></div><div><div>control(Port, Command, Data) -></div><div> control(port_control(Port, Command, Data)).</div><div><br></div><div>control(<<0, Result/binary>>) -></div><div> control(Result, true);</div><div>control(<<1, Error/binary>>) -></div><div> control(Error, false).</div><div><br></div><div>control(<<Error/binary>>, false) -> % <--- LINE 492</div><div> {error, binary_to_term(Error)};</div><div>control(<<Result/binary>>, true) -></div><div> Result.</div></div></span>
</div>
<br></div><div><br></div><div>Anyway, thanks for your explanations Björn.</div><br><div apple-content-edited="true">
<div>Regards,</div><div>Zabrane</div>
</div>
<br></body></html>