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
    possible duplicate of [How much RAM does each character in ECMAScript/JavaScript string consume?](http://stackoverflow.com/questions/7217015/how-much-ram-does-each-character-in-ecmascript-javascript-string-consume) – jAndy Mar 06 '13 at 23:13

2 Answers2

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

Daniel Williams
  • 8,673
  • 4
  • 36
  • 47
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.

Community
  • 1
  • 1
Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74