[erlang-questions] Erlang string datatype [cookbook entry #1 - unicode/UTF-8 strings]
Fri Oct 28 00:20:43 CEST 2011
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.
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).
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.
On Tue, Oct 25, 2011 at 1:04 AM, Loïc Hoguin <essen@REDACTED> wrote:
> On 10/25/2011 09:57 AM, Anthony Ramine wrote:
> > Le 25 oct. 2011 à 06:57, Richard O'Keefe a écrit :
> >>> 6) Ideally, reference count immutable string data so that substring
> extraction is cheap.
> >> Java has cheap substring extraction without reference counting.
> >> However, be aware that doing this can lead to *huge* space leaks with
> >> large source strings being retained for the sake of comparatively small
> >> substrings; there is a *reason* why Java's immutable String class comes
> with a
> >> copy() method!
> > Don't we have the same problem with sub-binaries of large binaries?
> > (Sorry for the dupe mail Richard, forgot to include the list)
> And that's why binaries come with a binary:copy/1 function.
> Loïc Hoguin
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions