
Ok I think this sucks. :-) Here is my code to implement zlib compression/decompression via boost. However since is uses streams I cannot simply pass a buffer. This code is intended for compress socket buffers, but is pathetically slow. HAs anyone done this? What can I improve? The copy seems to be the bottle neck. thx jc Here is my code: #include <boost/iostreams/copy.hpp> #include <boost/iostreams/filter/zlib.hpp> #include <boost/iostreams/device/file.hpp> #include <boost/iostreams/stream.hpp> #include <boost/iostreams/filtering_stream.hpp> #include <boost/iostreams/detail/config/zlib.hpp> using namespace boost::iostreams; std::string compress(std::string data) { std::stringstream compressed; std::stringstream decompressed; decompressed << data; boost::iostreams::filtering_streambuf<boost::iostreams::input> out; out.push(boost::iostreams::zlib_compressor()); out.push(decompressed); boost::iostreams::copy(out, compressed); return compressed.str(); } std::string decompress(std::string data) { std::stringstream compressed; std::stringstream decompressed; compressed << data; boost::iostreams::filtering_streambuf<boost::iostreams::input> out; out.push(boost::iostreams::zlib_decompressor()); out.push(compressed); boost::iostreams::copy(out, decompressed); return decompressed.str(); } int main() { std::string data = compress("boo!"); std::cout << data << std::endl; std::cout << decompress(data) << std::endl; return 0; }