String class allocating on stack for small strings?

后端 未结 4 1712
臣服心动
臣服心动 2021-01-17 20:25

Do anyone know if there is a STL interface compatible string class that allocates memory for small strings on the stack (up to a certain threshold) and the heap for larger s

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-17 20:40

    You can provide a custom allocator for std::basic_string (it is the third template argument). This answer explains how use that and links to an implementation of a stack-allocator that can be used.

提交回复
热议问题