boost-iostreams

Memory usage when using boost::iostreams::mapped_file

混江龙づ霸主 提交于 2019-11-30 06:06:45
问题 I am pasting some code here which uses boost iostream to mmap & then writes to the mapped file: typedef unordered_map<int, string> work; int main() { work d; d[0] = "a"; boost::iostreams::mapped_file_params params; params.path = "map.dat"; params.new_file_size = 1000000000; params.mode = (std::ios_base::out | std::ios_base::in); boost::iostreams::mapped_file mf; mf.open(params); work* w = static_cast<work*>((void*)mf.data()); w[0] = d; for(int i=1; i <1000000000 ;++i) { w->insert(std::make

How to bind program termination with end-of-stream in Boost.Process 0.5?

不羁岁月 提交于 2019-11-29 03:55:00
In this simple example of Boost.Process 0.5 ( http://www.highscore.de/boost/process0.5/index.html ) the output of a program ( ls ) is feeding a stream. The stream works fine but contrary to the expectation the stream doesn't become invalid (e.g. end-of-stream) after the program finishes (similar to previous version of Boost.Process, e.g. http://www.highscore.de/boost/process/index.html ) What am I missing in order to make the stream ( is in the example) automatically invalid after child program exits? Perhaps is it an option that I have to set in the Boost.Streams stream of file_descriptor ?

Does Boost.Serialization serialize differently on different platforms?

余生颓废 提交于 2019-11-29 03:45:16
I use Boost.Serialization to serialize a std::map. The code looks like this void Dictionary::serialize(std::string & buffer) { try { std::stringstream ss; boost::archive::binary_oarchive archive(ss); archive << dict_; buffer = ss.str(); } catch (const std::exception & ex) { throw DictionaryException(ex.what()); } } void Dictionary::deserialize(const char * const data, int length) { try { namespace io = boost::iostreams; io::array_source source(data, length); io::stream<io::array_source> in(source); boost::archive::binary_iarchive archive(in); archive >> dict_; } catch (const std::exception &

How to build boost iostreams with gzip and bzip2 support on Windows

两盒软妹~` 提交于 2019-11-28 17:14:08
问题 How do I build boost 's iostreams library with gzip and bzip2 support? 回答1: I am no expert, but this worked for me. Option 1 (straight from source) Download source files for zlib and for bzip2. Extract the downloads to directories, move directories to somewhere you like. I had to avoid C:\Program Files (x86)\ as I couldn't get it to work with spaces in the directory name, so I created C:\Sys\ and used that. Open a command prompt with elevated privileges (run as administrator), go to your

How to hook up Boost serialization & iostreams to serialize & gzip an object to string?

六月ゝ 毕业季﹏ 提交于 2019-11-28 16:33:38
I've been using the Boost serialization library, which is actually pretty nice, and lets me make simple wrappers to save my serializable objects to strings, like so: namespace bar = boost::archive; namespace bio = boost::iostreams; template <class T> inline std::string saveString(const T & o) { std::ostringstream oss; bar::binary_oarchive oa(oss); oa << o; return oss.str(); } template <class T> inline void saveFile(const T & o, const char* fname) { std::ofstream ofs(fname, std::ios::out|std::ios::binary|std::ios::trunc); bar::binary_oarchive oa(ofs); oa << o; } template <class T> inline void

How to bind program termination with end-of-stream in Boost.Process 0.5?

*爱你&永不变心* 提交于 2019-11-27 22:13:44
问题 In this simple example of Boost.Process 0.5 ( http://www.highscore.de/boost/process0.5/index.html) the output of a program ( ls ) is feeding a stream. The stream works fine but contrary to the expectation the stream doesn't become invalid (e.g. end-of-stream) after the program finishes (similar to previous version of Boost.Process, e.g. http://www.highscore.de/boost/process/index.html) What am I missing in order to make the stream ( is in the example) automatically invalid after child program

Using boost::iostreams::tee_device?

旧时模样 提交于 2019-11-27 21:37:49
Can someone help me? I am trying to do something like the following: #include <boost/iostreams/tee.hpp> #include <boost/iostreams/stream.hpp> #include <sstream> #include <cassert> namespace io = boost::iostreams; typedef io::stream<io::tee_device<std::stringstream, std::stringstream> > Tee; std::stringstream ss1, ss2; Tee my_split(ss1, ss2); // redirects to both streams my_split << "Testing"; assert(ss1.str() == "Testing" && ss1.str() == ss2.str()); But it won't compile in VC9: c:\lib\boost_current_version\boost\iostreams\stream.hpp(131) : error C2665: 'boost::iostreams::tee_device<Sink1,Sink2

C++ “hello world” Boost tee example program

邮差的信 提交于 2019-11-27 14:24:59
The Boost C++ library has Function Template tee The class templates tee_filter and tee_device provide two ways to split an output sequence so that all data is directed simultaneously to two different locations. I am looking for a complete C++ example using Boost tee to output to standard out and to a file like "sample.txt". Based on help from the question John linked: #include <boost/iostreams/tee.hpp> #include <boost/iostreams/stream.hpp> #include <fstream> #include <iostream> using std::ostream; using std::ofstream; using std::cout; namespace bio = boost::iostreams; using bio::tee_device;

How to hook up Boost serialization & iostreams to serialize & gzip an object to string?

别说谁变了你拦得住时间么 提交于 2019-11-27 09:46:43
问题 I've been using the Boost serialization library, which is actually pretty nice, and lets me make simple wrappers to save my serializable objects to strings, like so: namespace bar = boost::archive; namespace bio = boost::iostreams; template <class T> inline std::string saveString(const T & o) { std::ostringstream oss; bar::binary_oarchive oa(oss); oa << o; return oss.str(); } template <class T> inline void saveFile(const T & o, const char* fname) { std::ofstream ofs(fname, std::ios::out|std:

Using boost::iostreams::tee_device?

Deadly 提交于 2019-11-27 04:32:24
问题 Can someone help me? I am trying to do something like the following: #include <boost/iostreams/tee.hpp> #include <boost/iostreams/stream.hpp> #include <sstream> #include <cassert> namespace io = boost::iostreams; typedef io::stream<io::tee_device<std::stringstream, std::stringstream> > Tee; std::stringstream ss1, ss2; Tee my_split(ss1, ss2); // redirects to both streams my_split << "Testing"; assert(ss1.str() == "Testing" && ss1.str() == ss2.str()); But it won't compile in VC9: c:\lib\boost