5 ms·
I suppose it could allocate an extra byte anyway, and set that byte to null. It seems like that could cause issues with memory alignment if you go thinking ever
by byuu 15y ago
I suppose it could allocate an extra byte anyway, and set that byte to null. It seems like that could cause issues with memory alignment if you go thinking every string is 256-bytes, but it's 257-bytes because of that. Not that big of a deal, of course.
The length value in that case would also be invalid for C usage, because std::string does allow storing nulls inside the string, but it would eliminate the need for allocation.