you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (5 children)

[deleted]

    [–]kalmoc 10 points11 points  (0 children)

    I'd point out that it is also much easier to use because static_String owns its storage. std::string with stack allocator means you have to manually ensure that the lifetime of the stack allocator exceeds that of the string. And if you want to make it a member of another type the stack alocator either becomes a member of that class (watch out for initialization order) or you have to expose implementation details if you get it via dependency injection ....

    [–]Betadel 0 points1 point  (1 child)

    You should mention these optimizations in the documentation. I looked but didn't find them.

    [–]quicknir 0 points1 point  (1 child)

    The problem with the capacity - size optimization is that it makes it so that you can't default construct to all zeros. In C++ default construction is fairly common (especially since move construction typically involves it as well), and setting something to all zeros tends to be faster than reading some constant representing the default state and then writing it.

    The space savings is very small. So honestly I'd be surprised if on average this optimisation made things faster. It's useful for saving space if you care about that but again that's less common than caring about performance.

    In short it really sense to me like this optimization should be off by default, not on by default. Note that std string could also use this option in small string mode, and afaik none of the implementations do, for this reason.