Boost logo

Boost Users :

Subject: Re: [Boost-users] boost replacement for std::ostringstream
From: Chris Stankevitz (chrisstankevitz_at_[hidden])
Date: 2012-09-07 17:58:56


On Fri, Sep 7, 2012 at 2:09 PM, Szymon Gatner <szymon.gatner_at_[hidden]> wrote:
> May I ask tho: why are you using a stream to write a block of memory
> to a string? Why not just directly copying it to a vector (or a
> string)?

These are good questions. The short answer is I am
pseudo-profiling... aka profiling by "divine inspiration" rather than
actually looking at the results of a profiler... which is often a
waste of time but this time seemed to help.

My original code wrote many small batches of binary data to std::cout
(think hundreds of thousands of calls to std::cout::write). I
modified the routine to use boost's filtering_ostream to write many
small blocks to a string. Then write that string to stdout with just
one call to std::cout::write. This reduced the number of calls to
std::cout::write by a factor of 100,000 or so.

In my real case, unlike the example I posted here, the data I am
writing is not from one contiguous block.

Thank you!

Chris


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net