Re:Appending to an std:string character-by-character: how do...
by jltsiren on Thursday October 26, 2023 @10:05PM
(#38033868)
Allocation size is capacity + 1. If you double the allocation size to 2 * (capacity + 1), the new capacity is 2 * capacity + 1.
[ Parent
| on HN ]
Re:Appending to an std:string character-by-character: how do...
by anonymoushn on Friday October 27, 2023 @12:41AM
(#38034766)
Surely 2 * (capacity + 1) = 2 * capacity + 2
Re:Appending to an std:string character-by-character: how do...
by jltsiren on Friday October 27, 2023 @01:38AM
(#38035064)
That is the new allocation size. The new capacity is one character less. The allocation must include space for the trailing 0, which is not a part of the string and is hence not included in the length/capacity numbers.
Re:Appending to an std:string character-by-character: how do...
by anonymoushn on Friday October 27, 2023 @02:27AM
(#38035309)
I see, thanks for your patience :)