Could String internalize an ArrayBuffer?
isiahmeadows at gmail.com
Sun Dec 6 07:06:35 UTC 2015
On Sun, Dec 6, 2015 at 12:19 AM, Boris Zbarsky <bzbarsky at mit.edu> wrote:
> On 12/5/15 8:44 AM, Coroutines wrote:
>> What I want is to be able to view a String through a typed array
>> without duplicating the memory/contents of that string.
> The big problem with this is that the actual in-memory representations of
> strings and arraybuffers can be quite different in implementations right
> For example, strings typically have a complicated representation that
> involves multiple fragments, ropes, etc, to make string concatenation fast.
> Not only that, but to save memory in various engines some strings that only
> contain values less than 256 are stored with underlying 8-bit units, not
> 16-bit ones. There has also been talk of using something like UTF-8 for the
> internal string representation in some engines, to reduce the impedance
> mismatch with engine consumers (like a browser rendering engine).
AFAIK most engines already do this.
> Arraybuffers, on the other hand, are typically an actual contiguous chunk of
> memory to make access fast. And of course they just exposed whatever bytes
> they contain.
And V8, if I understand correctly, uses effectively a linked tree
(closer to a web) of single-character pairs for their strings. This is
not at all contiguous, but makes string slicing and building very
cheap to do. The only realistic way to have a string stored in an
ArrayBuffer is to have it encoded like a C string (er... `char*`).
> es-discuss mailing list
> es-discuss at mozilla.org
More information about the es-discuss