3 ms·
It's always tradeoffs. If by "arrays of codepoints" you mean "each element of the array is a single codepoint", then you get O(1) indexing regarding codepoints
by steveklabnik 9y ago
It's always tradeoffs.
If by "arrays of codepoints" you mean "each element of the array is a single codepoint", then you get O(1) indexing regarding codepoints, but may use up to 4x the memory as the variable-length encoding.
- bumblebritches5 9y agoWhich is fine when you're doing nothing but a simple operation on a string, then reencoding it. Seriously, how many strings have you ever ran across that are more than 1kb? how many strings have you ran across that are more than 256 codepoints?
- steveklabnik 9y agoSure. It's fine sometimes, and not fine other times. That's why it's called a tradeoff. I see strings larger than that all the time, and care about using low RSS. YMMV.
- nirvdrum 9y agoPeople routinely read text files larger than 1 KB into memory. HTTP responses are often larger than 1 KB. Serialized data (JSON, XML, etc.) is often larger than 1 KB.
- bumblebritches5 9y agoHTTP headers are not anywhere near 1kb of text. the packet's themselves are only 1.5kb.
- nirvdrum 9y agoThe headers are one component of a response. The body is often larger than 1 KB.
- bumblebritches5 9y agoand your whole packet is text, without any compression? I doubt that.
- mromanuk 9y agoI’m currently working with a 2 MB string, representing 150k words, with a structure that is a Packed Trie stored as an array for fast access of Unicode Scalars in Swift
- bumblebritches5 9y agoWhy would you use a string to store that in the first place? if you're editing text, make a structure that contains just words, sentences, paragraphs with smaller more manageable strings in there. There's no reason for a single string to contain that much data.