16 Şubat 2018 Cuma

interprocess bufferstream Sınıfı

Giriş
Şu satırı dahil ederiz.
#include <boost/interprocess/streams/bufferstream.hpp>
Stream olarak kullanılabilir ancak sahred memory alanına yazar ve okur.

Constructor - std::ios::out
Yazmak için şöyle yaparız.
bip::shared_memory_object shm(bip::create_only, "SharedMemory", bip::read_write);

shm.truncate(10u<<20); // 10MiB
bip::mapped_region region(shm, bip::read_write); 

bip::bufferstream bs(std::ios::out);
bs.buffer(reinterpret_cast<char*>(region.get_address()), region.get_size());
boost::archive::text_oarchive oa(bs);
Constructor - std::ios::in
Okumak için şöyle yaparız.
bip::shared_memory_object shm(bip::open_only, "SharedMemory", bip::read_only);
bip::mapped_region region(shm, bip::read_only); 

bip::bufferstream bs(std::ios::in);
bs.buffer(reinterpret_cast<char*>(region.get_address()), region.get_size());
boost::archive::text_iarchive ia(bs);



Hiç yorum yok:

Yorum Gönder