String class allocating stack for small strings?

Does anyone know if there is an STL compatible string class that allocates memory for small lines in the stack (up to a certain threshold) and a bunch for large lines?

I am looking for program optimization, and I use the allocation of small local lines that can easily fit on the stack, instead of being allocated in a heap.

+8
c ++ string memory-management stl wstring
source share
4 answers

You can provide a custom allocator for std::basic_string (this is the third argument to the template). This answer explains how to use this and refers to the implementation of the stack allocator used.

+1
source share

The implementation of vstring (__versa_string) from gcc can do a little string optimization and has a std string interface. If you use gcc, just enable ext / vstring. Otherwise, you can adapt it to your compiler / environment.

+1
source share

This is an antique question, but I feel that it is better than any of the current answers.

http://llvm.org/docs/ProgrammersManual.html#dss_smallstring

This is basically what you want. BTW tcmalloc increased performance in my (poorly designed: D) sequence with an intensive program intensity of 10%. You also need a profile to prove that allocs is your performance.

+1
source share

__ versa_string The SSO version can store no more than 15 bytes on the stack, and if that happens, it reserves 16 bytes regardless of the size of the string ( http://codepad.org/2M7N9cTu ).

http://www.and.org/ustr/ may reuse the stack buffer, but I am having trouble communicating with the Debian Wheezy 64bit.

http://freecode.com/projects/str-class can reuse the stack buffer.

I wrote a line class only for the header, which uses only four bytes and can reuse the stack buffer: http://code.google.com/p/libglim/source/browse/trunk/gstring.hpp
It has limited STL compatibility: basic_streambuf is implemented for use with std :: ostream.

0
source share

All Articles