4 ms·
Most memory allocators have an internal fragmentation which removes most efficiency gained by zero-termination. In fact it's worse, because zero-termination mea
by lifthrasiir 4y ago
Most memory allocators have an internal fragmentation which removes most efficiency gained by zero-termination. In fact it's worse, because zero-termination means that deallocation can't take a size parameter and it can often cause a performance hit for many modern allocators due to cache misses [1].
[1] https://isocpp.org/files/papers/n3778.html https://isocpp.org/files/papers/n3778.html
- jstimpfle 4y agozero-terminated says nothing about allocation, so there's that.
- lifthrasiir 4y agoYou were talking about [space] efficiency for small strings, which is inherently related to the memory allocation scheme.
- jstimpfle 4y agoWhat? You can allocate zero-terminated strings in .rodata by typing "a string literal" in source code, for example. It's fair to say that there's no fragmentation or whatever and you don't have to think about deallocation either. Other popular approaches to allocate strings dynamically would generally group strings of similar lifetime or by size, amortizing possible overheads over many strings. If your favorite memory allocator requires a size field to support efficient deallocation, then by all means put that in the allocation record. But this is totally orthogonal to the format of a simple string representation.
- deleted 4y ago[deleted]