[erlang-questions] Warning: NOT OPTIMIZED: sub binary is used or returned
Zabrane Mickael
zabrane3@REDACTED
Tue Aug 7 14:03:31 CEST 2012
Hi Björn,
On Aug 7, 2012, at 8:24 AM, Björn Gustavsson wrote:
> On Mon, Aug 6, 2012 at 6:36 PM, Zabrane Mickael <zabrane3@REDACTED> wrote:
>> Hi guys,
>>
>> I'm communicating with linked-in driver using the following code:
>>
>> control(Port, Command, Data) ->
>> case port_control(Port, Command, Data) of
>> <<0, Result/binary>> -> Result; % <- LINE 468 handle a good case
>> <<1, Error/binary>> -> {error, binary_to_term(Error)} % <- LINE 469 handle error case
>> end.
>>
>>
>> When compiling, I got this 02 warnings:
>>
>> $ make
>> Recompile: src/pimco.erl
>> src/pimco.erl:468: Warning: NOT OPTIMIZED: sub binary is used or returned
>> src/pimco.erl469: Warning: NOT OPTIMIZED: sub binary used by erlang:binary_to_term/1
>> make[2]: Nothing to be done for `all'.
>>
>> Is there a way to get rid of these warnings and avoid a full binary copies?
>
> Yes, you can get rid of the warnings by *not* using the bin_opt_info compiler
> option.
;-)
> No, there is nothing to avoid here. The warning says that
> a sub binary is created. A sub binary is small term that
> references a part of a binary. Sub binaries is usually an
> efficient way to reference just a part of a binary.
>
> So there is *no* copying of the binary data going on in
> your example.
Crystal clear.
This version is funny because the compiler now throws only one WARNING instead of two:
$ make
src/pimco.erl:492: Warning: NOT OPTIMIZED: sub binary is used or returned
control(Port, Command, Data) ->
control(port_control(Port, Command, Data)).
control(<<0, Result/binary>>) ->
control(Result, true);
control(<<1, Error/binary>>) ->
control(Error, false).
control(<<Error/binary>>, false) -> % <--- LINE 492
{error, binary_to_term(Error)};
control(<<Result/binary>>, true) ->
Result.
Anyway, thanks for your explanations Björn.
Regards,
Zabrane
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120807/3ce8e3ec/attachment.htm>
More information about the erlang-questions
mailing list