August 2017
Intermediate to advanced
438 pages
14h 19m
English
Fixing it is very simple; we need only to replace the pointer with offset_ptr<>:
#include <boost/interprocess/offset_ptr.hpp> struct correct_struct {
boost::interprocess::offset_ptr<int> pointer_;
// ...
int value_holder_;
};
Now, we are free to use it like a usual pointer:
int main() { boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create, "segment", 4096); correct_struct* ptr = segment.find<correct_struct>("structure").first; if (ptr) { std::cout << "Structure found\n"; assert(*ptr->pointer_ == ethalon_value); segment.destroy<correct_struct>("structure"); }}
Read now
Unlock full access