Boost logo

Boost Users :

From: Rodrigo Baroni (rodrigobaroni_at_[hidden])
Date: 2005-12-12 10:42:50


    I just have one doubt now: The output to a std::string (that has
internal variable size, and so, maybe use some linked queue, or
whatever I guess), or to output to a pre-alocated buffer?

     Shouldn't be, in some cases where this task is done a lot of
times in a loop (like is the case - where I'm doing compression of
frames in a streaming video server) be more faster and better to
output to memory directly in a pre-alocated buffer?

=> Case 1: output to memory-pre-alocated-stream-output:

> > //--------------- Compress the content of buffer to
> > compressedBuffer----------------------
> >
> > char buffer = "Helloooo compressed filter example!";
> > int SIZE = 10000;
> >
> > char compressedBuffer = new char [ SIZE ];
> >
> > io::stream< io::array_source > bufferStream( buffer, std::strlen(
> > buffer ) ); io::stream< io::array_sink > compressedBufferStream(
> > &compressedBuffer, SIZE );
> >
> > io::filtering_ostream compressFilterOutput;
> > compressFilterOutput.push( io::zlib_compressor( ) );
> > compressFilterOutput.push( compressedBufferStream );
> >
> > io::copy( bufferStream, compressedFilterOutput );
> > compressedBufferStream.flush( );
> > compressFilterOutput.reset( );
> >
> > //-----------------------------

=> Case 2: output to std::string dynamic-allocated-stream-output:

>
> Here's a simpler way to accomplish the above:
>
> #include <iterator>
> #include <string>
>
> std::string compressed;
> io::filtering_ostream
> out( io::zlib_compressor() |
> std::back_inserter(compressed) );
> out.write(buffer, std::strlen(buffer));
> out.reset();
>
> Now you can query the length with compressed.size().

 Thanks in advance,
Rodrigo F. Baroni


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