Hacker News new | ask | show | jobs
by levzettelin 595 days ago
tl;dr

They made a C++ string type, let's call it "german_string", with sizeof(german_string) == 16. german_string can be in SSO mode (4 byte size field plus 12 SSO bytes) or in long string mode. In long string mode, they still use 4 bytes for the size, store no capacity (capacity is always equal to size), use another 4 bytes to always store the prefix of the string (this avoids a memory indirection in many cases when doing string comparisons), plus the pointer. Furthermore, a long string mode german_string can also act as a string_view or a string_view to ".rodata"; this is called the "string class". The string class is stored in two bits stolen from the 8 byte pointer.