8

I'm storing a very large ( >1MB ) bitmask in memory as a string and am curious about how JS stores strings internally. I have the feeling, based on the fact that

String.fromCharCode( 65535 ).charCodeAt( 0 ) === 65535

, that all strings are unicode, but I'm not certain. Basically I'm trying to find out if it would be more efficient, in terms of memory usage, to bitmask against 16-bit characters than 8-bit characters?

1

2 Answers 2

1

Check this out:

https://developer.mozilla.org/en-US/docs/Mozilla_internal_string_guide#IDL_String_types

I believe it is very very browser dependent but the Mozilla documentation sheds some light on how they do it internally for JS strings.

The short answer is they use UTF-16

http://en.wikipedia.org/wiki/UTF-16

Sign up to request clarification or add additional context in comments.

Comments

0

Check out this discussion.

JavaScript strings - UTF-16 vs UCS-2?

In short, just because some Javascript engines use a 16 bit encoding does NOT make it UTF16. Edge case surrogate pairs are handled MUCH differently between the two.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.