#include #include #include #include #ifdef USE_BZIP2 # include #else # include #endif int main (int argc, char** argv) { int loops(NUM_LOOPS); if (argc > 1) { loops = atoi(argv[1]); } std::string testData = "\n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ "; std::cerr << "Test data : " << testData << std::endl; int i(0); try { for (i = 0; i < loops; ++i) { if (!(i % 1000)) { std::cerr << i << ' '; } std::istringstream ifs(testData); std::ostringstream toFS; boost::iostreams::filtering_ostream ofs; #ifdef USE_BZIP2 ofs.push(boost::iostreams::bzip2_compressor()); #else // this line causing the bad_alloc exception ofs.push(boost::iostreams::zlib_compressor()); #endif ofs.push(toFS); boost::iostreams::copy(ifs, ofs); ofs.reset(); } } catch (const std::exception& e) { std::cerr << std::endl << "Caught std::exception on iteration " << i << ": " << e.what() << std::endl; } if (i == loops) { std::cerr << std::endl << "TEST OK on " << i << " iterations" << std::endl; } else { std::cerr << std::endl << "TEST FAILED on iteration " << i << std::endl; } return 0; }