4 ms·
> That’s not cache-friendly, though. How so? The string implementations in that post are pretty much that: struct string { char* ptr;
by Joker_vD 7mo ago
> That’s not cache-friendly, though.
How so? The string implementations in that post are pretty much that:
struct string
{
char* ptr;
size_t size;
union {
size_t capacity;
char buf[16];
};
The pointer and the size are stored together, and they may optionally be located right next to the string's actual data, but only for very small, locally-allocated, short-lived strings; but in normal usage, that pointer points somewhere into the heap.
- Someone 7mo ago> they may optionally be located right next to the string's actual data, but only for very small, locally-allocated, short-lived strings Only for small strings. Locally allocated and short-lived aren’t required for short string optimization to take an effect. Also, I can’t find a good reference, but “only for small strings” in many programs means “for most strings”.