Reputation: 28689
Can't seem to find anything currently available in the wild, which seems odd.
So before I roll my own, does anyone know of a std compliant stringstream which allocates storage on the stack?
I'm thinking of 2 ways to achieve this:
Initially use a statically sized buffer on the stack (probably a template parameter to allow compile-time customization)
alloca
to increase the stack storageThis will allow quick input into a stringstream for strings shorter than the predetermined size.
A suitable choice for the initial size will mean that things like logging can be achieved without frequent resizing from the heap.
Upvotes: 4
Views: 1828
Reputation: 283793
You can get the same benefits by using std::basic_stringbuf<char, char_traits<char>, pooled_allocator>
, where you only have to write the pooled allocator.
Then just create a basic_iostream
attached to that buffer.
Or, create a new class derived from basic_streambuf
.
But don't rewrite stringstream
. The iostreams library is designed by extension by replacing the buffer object.
Upvotes: 4