Std compatible stringstream using dedicated storage on the stack?

It seems that there is nothing available in the wild that seems strange.

So, before I give up on my own, does anyone from the std-compatible string stream know which allocates storage on the stack?

I think of two ways to achieve this:

Initially use a static buffer size on the stack (perhaps a template parameter for setting compilation time)

  • When the run ends, return to using dynamic storage
  • When space runs out, use alloca to increase stack storage

This will allow you to quickly enter a string stream for lines shorter than the specified size.

A suitable choice for the initial size will mean that things like logging can be achieved without frequently resizing from the heap.

+4
source share
1 answer

You can get the same benefits using std::basic_stringbuf<char, char_traits<char>, pooled_allocator> , where you only need to write a merged allocator.

Then just create a basic_iostream attached to this buffer.

Or create a new class derived from basic_streambuf .

But do not rewrite stringstream . The iostreams library was developed by the extension by replacing the buffer object.

+4
source

Source: https://habr.com/ru/post/1387805/


All Articles