Search code examples
performancefileboostboost-asiostreambuf

C++: Best text accumulator


Text gets accumulates piecemeal before being sent to client.

Now we use own class that allocates memory for each piece as char massive. (Anyway, works like char[][] + std::list<char*>).

Then we build the whole string, convert it into std::sting and then create boost::asio::streambuf using it. That's slow enough, I assume. Correct me if I'm wrong.

I know, in many cases simple FILE type from stdio.h is used. How does it works? Allocates memory at every write into it. So, is it faster and is there any way to read into boost::asio::streambuf from FILE?

ADD: Hm. I've forgot one big thing :). The compilation of dlls and main application is made under few compilers, so it should have no stl stuff inside it ... Because it usually cause a lot of problems, while executing dlls.


Solution

  • I have no idea how efficient it is, but I usually use a ostringstream for that sort of thing