Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To avoid confusion let me restate the problem.</p> <p>You want to create an object in mapped memory in such a way that after the application is closed and reopened the file can be mapped once again and object used without further deserialization.</p> <p>POD is kind of a red herring for what you are trying to do. You don't need to be binary copyable (what POD means); you need to be address-independent.</p> <p>Address-independence requires you to:</p> <ul> <li>avoid all absolute pointers.</li> <li>only use offset pointers to addresses within the mapped memory.</li> </ul> <p>There are a few correlaries that follow from these rules.</p> <ul> <li>You can't use <code>virtual</code> anything. C++ virtual functions are implemented with a hidden vtable pointer in the class instance. The vtable pointer is an absolute pointer over which you don't have any control.</li> <li>You need to be <em>very</em> careful about the other C++ objects your address-independent objects use. Basically everything in the standard library may break if you use them. Even if they don't use <code>new</code> they may use virtual functions internally, or just store the address of a pointer.</li> <li>You can't store references in the address-independent objects. Reference members are just syntactic sugar over absolute pointers.</li> </ul> <p>Inheritance is still possible but of limited usefulness since virtual is outlawed.</p> <p>Any and all constructors / destructors are fine as long as the above rules are followed.</p> <p>Even Boost.Interprocess isn't a perfect fit for what you're trying to do. Boost.Interprocess also needs to manage shared access to the objects, whereas you can assume that you're only one messing with the memory.</p> <p>In the end it may be simpler / saner to just use <a href="https://code.google.com/apis/protocolbuffers/" rel="nofollow">Google Protobufs</a> and conventional serialization.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload