How do they do that? As string lengths can vary. One way might be to store the continuous strings in memory and then maintain an array of pointers to those strings. But then we are back to pointers.
Searched google. Didn't find anything.
How do they do that? As string lengths can vary. One way might be to store the continuous strings in memory and then maintain an array of pointers to those strings. But then we are back to pointers.
Searched google. Didn't find anything.
But you can be smarter than that. As it happens, I just implemented "vector of strings" where all strings are contiguous in memory.
The code: https://github.com/sumatrapdfreader/sumatrapdf/commit/bc8311...
The basic idea is like you said: you keep strings contiguously in memory and maintain a separate array of pointers to each string. Except it's not a pointer but u32 index into that block of memory.
Even if those were pointers, not the u32 indexes, it would still be cache friendly.
The point is that strings are close together.
If each string was allocated with malloc() then you don't control where they are allocated.
In the worst case each string could end up in a separate cache line, which would be much slower if you were to iterate over all strings.
The data will stay contiguous as long as it's constant/read only.
But as soon as you start to use it and change it for doing some real work, it will get scattered.