2008/11/24 Vance Shipley <span dir="ltr"><<a href="mailto:vances@motivity.ca">vances@motivity.ca</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Robert,<br>
<br>
My thinking was that reading a big binary and then passing it<br>
with offsets to various parsing functions would be easier on<br>
the emulator than creating a new binary for each one. Is it<br>
the case that the compiler will optimize away the creation of<br>
these binaries?<br>
<font color="#888888"></font></blockquote><div><br>No, I don't think so. It optimises the following case:<br><br>foo(<< ... , Rest/binary>>, ... ) -><br> ...<br> bar(Rest, ...);<br><br>The important thing is that the old reference to the binary is not used again and can be reused by the compiler. If you have a big binary and want to pass off chunks of it to different functions is a different problem. Then it is probably better to pass the whole binary and an offset. However, doing something like:<br>
<br>foo(Offset, Bin, ...) -><br> << _:Offset/binary, Stuff, _/binary>> = Bin,<br> ...<br> foo(Offset + N, Bin, ...)<br><br>and skipping over the beginning each time is most likely not the best way to step over bits of your chunk. I would do something like:<br>
<br>foo(Offset, Bin, ...) -><br> << _:Offset/binary,TheGoodBit/binary >> = Bin,<br> foo1(TheGoodBit, ...).<br><br>and foo1 as my first example above which picks bit off the head of the bin.<br><br>Robert<br>
<br></div></div>