Null-terminated strings are slower than the alternative. A (pointer, length) representation allows slicing (including tokenizing / parsing) without allocation, avoids seeks to the end and is more friendly to SIMD operations. The same code gets reused for slices of any type, not just strings. A slice can point into any memory, including into a dynamic array or just a smaller range of another slice.
View all comments
Show parent comment
15
u/[deleted] Sep 04 '14
Null-terminated strings are slower than the alternative. A
(pointer, length)representation allows slicing (including tokenizing / parsing) without allocation, avoids seeks to the end and is more friendly to SIMD operations. The same code gets reused for slices of any type, not just strings. A slice can point into any memory, including into a dynamic array or just a smaller range of another slice.