|
Boost Users : |
From: Jason Sachs (jmsachs_at_[hidden])
Date: 2008-04-28 17:40:27
I'm trying to wrap my head around how I would implement a vector of unions
of strings/integers/doubles in shared memory. (for those familiar with
Micro$oft COM, this would essentially be a SAFEARRAY of VARIANTs)
I got a quick example of shared memory working & seem to have a decent
handle on the basics. I guess there are two things that I'm not quite
confident in:
(1) how to make a containable element work nicely within shared memory, e.g.
if I have a structure S that needs to allocate shared memory dynamically
during its lifetime (and automatically deallocate upon destruction), how do
I store the allocator? (or do I?) If I allocate the memory myself and store
it in an offset_ptr<>, I can do that, but I need it to manage the shared
memory itself. In particular, one process may need to construct some
anonymous object X within the shared memory segment and store the result in
an offset_ptr<>, and another process may be the one destroying the memory of
X later on.
(2) unions or Boost.Variant that would work with shared memory-- gack!
I am looking for insight both into the general case (all elements of the
vector are polymorphic, vector size can vary) and the following specific
case: I have a fixed-size vector, format "defined" at runtime using an array
of enums that designate the type of variable that can be stored in each
element of the vector. If it weren't for string support, I would just
allocate a fixed-size chunk of memory rather than a vector, and do all the
management within the chunk myself by calculating element size + offsets +
what have you, which I've done before in other contexts. I can still do that
if I can store a handle to the string (e.g. an offset into the shared memory
segment?) rather than a pointer or other high-level object, so that my
"vector" object becomes a class that just has to know how to
allocate/deallocate memory on its own (hence question #1 still needs an
answer, but I can avoid question #2).
p.s. there seems to be a lot of missing methods in the documentation for
shared_memory_object and managed_shared_memory (e.g. allocate(),
construct(), destroy(), destroy_ptr()). Or am I missing something?
http://www.boost.org/doc/libs/1_35_0/doc/html/boost/interprocess/shared_memory_object.html
http://www.boost.org/doc/libs/1_35_0/doc/html/boost/interprocess/basic_managed_shared_memory.html
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net