Re: STL allocator for shared memory

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Joe wrote:
The problem will be that you have no control over how memory is utilized,
and more than likely an STL-allocated object will contain pointers -- when
stored in shared memory by the process that created the object these
pointer-values will be valid addresses, but not when accessed by other
processes.  Pointers stored in shared-memory need to be stored as offsets
from the base of shared memory.

With Dinkumware's implementation you can use a custom pointer type that contains an offset (using the allocator::pointer typedef). I've had offset pointers working in a container using their implementation, since it is very careful to always use the allocator typedefs rather than assuming that pointer == T*.


Tom
.



Relevant Pages

  • Re: data structures on shared memory?
    ... > I've got a bit of a complex data structure based on linked lists, ... If the shared memory occupies the same set of virtual ... The second principal method is to give up on pointers ... and use offsets instead. ...
    (comp.unix.programmer)
  • Re: copying C structures acroos different processors
    ... If I need to copy this structure to shared memory if I calculated ... rather than absolute pointers. ... int FOO_GetInt16BE; ...
    (comp.lang.c)
  • Re: problems with saving strings in a shared memory segment
    ... processes or else the pointers to these data 'will mean nothing tothe ... but i do not know how t serialise string data... ... In your case of shared memory you don't need to worry about ... Since there's char * within the ...
    (comp.os.linux.development.apps)
  • Re: Creating Generic Class To Handle Shared Memory
    ... > You must write your own allocator, and make sure that nothing, absolutely nothing, can ... really difficult pieces (allocation and based pointers). ... > which won't work in shared memory; RTTI may present a similar problem, ... >>API functions required for it. ...
    (microsoft.public.vc.mfc)
  • Re: Sharing a struct/class/pointer in the data_seg() of a dll?
    ... You can use shared memory, containing a struct or array of plain-old-data, ... CreateFileMapping and MapViewOfFile. ... Shared data cannot contain any pointers to *non-shared* addresses, ...
    (microsoft.public.vc.mfc)