4 ms·
I ran into this two years ago or so and it was massive - because I extracted small values from HTML microdata stored in files and read into strings, from which
by nosianu 5y ago
I ran into this two years ago or so and it was massive - because I extracted small values from HTML microdata stored in files and read into strings, from which I extracted those values. The entire file-contents strings remained in memory. I had an array of a thousand small values extracted from a thousand files, for example, I would end up with an array the size of all those files, not of the extracted values. A gigantic difference for my use case.
I ended up writing a hack-string-copy function "substrForceMemCopy" that forced the runtime to allocate a new string by using substr on one less character than I actually wanted and then adding that missing character to force creation of a new string.
Main part of the function:
return s.substr(start, length - 1) + s.charAt(start + length - 1);