Also, as long as the sub-binary is smaller than 64 bytes, the VM is perfectly allowed to do the extraction itself, because small binaries are process-local and thus can almost trivially be detected and extracted.<div><br></div>
<div>For example, I imagine the VM could keep a count of how many bytes are referenced within a large binary (in addition to the actual ref count), as a hint for when a large binary is unlikely to be beneficial to stay in RAM. Implementation idea sketch: When a local heap references a global binary but the total amount of referenced bytes within that binary is less than 50%, the local heap will extract the piece it needs and release the global reference. This would cause many degenerate cases to clean up themselves on reference/use/collection (whenever you trigger this mechanism).<br>
<div><br></div><div>Sincerely,</div><div><br></div><div>jw</div><div><br></div><div><br>--<br>Americans might object: there is no way we would sacrifice our living standards for the benefit of people in the rest of the world. Nevertheless, whether we get there willingly or not, we shall soon have lower consumption rates, because our present rates are unsustainable. <br>
<br>
<br><br><div class="gmail_quote">On Tue, Oct 25, 2011 at 1:04 AM, Loïc Hoguin <span dir="ltr"><<a href="mailto:essen@dev-extend.eu">essen@dev-extend.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 10/25/2011 09:57 AM, Anthony Ramine wrote:<br>
> Le 25 oct. 2011 à 06:57, Richard O'Keefe a écrit :<br>
><br>
>>> 6) Ideally, reference count immutable string data so that substring extraction is cheap.<br>
>><br>
>> Java has cheap substring extraction without reference counting.<br>
>> However, be aware that doing this can lead to *huge* space leaks with very<br>
>> large source strings being retained for the sake of comparatively small<br>
>> substrings; there is a *reason* why Java's immutable String class comes with a<br>
>> copy() method!<br>
><br>
> Don't we have the same problem with sub-binaries of large binaries?<br>
><br>
> (Sorry for the dupe mail Richard, forgot to include the list)<br>
<br>
</div>And that's why binaries come with a binary:copy/1 function.<br>
<font color="#888888"><br>
--<br>
Loïc Hoguin<br>
Dev:Extend<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div></div>