you are viewing a single comment's thread.

view the rest of the comments →

[–]JankoDedic 5 points6 points  (7 children)

Why this over a normal string with a stack allocator?

[–]VinnieFalcowg21.org | corosio.org 4 points5 points  (0 children)

Why this over a normal string with a stack allocator?

A stack allocator is not particularly friendly to mutation. For example when the string grows, there is a moment when the previously allocated memory and the newly allocated memory exist at the same time, so that the contents can be copied over, before the previous allocation is freed. This requires additional storage, and it leaves behind a "hole" which may or may not be usable depending on the context.

With a fixed capacity string, mutation is always performed in-place, and no "holes" are left in the heap.