Boost logo

Boost Users :

From: Wolfgang Hottgenroth (woho_at_[hidden])
Date: 2007-01-23 10:55:16


Hi,

after I go really quick help here from Ion, I've another question.

I managed it to implement a map<string, string> in shared memory and I'm
able to put pairs into the map in one process and read them in another
process.

To put pair into the map I wrote:

  typedef boost::interprocess::allocator<char,
boost::interprocess::managed_shared_memory::segment_manager>
ShmemStringAllocator;
  typedef boost::interprocess::basic_string<char, char_traits<char>,
ShmemStringAllocator> MyString;

  MyString key(segment.get_segment_manager());
  MyString value(segment.get_segment_manager());

  key = "key1";
  value = "value1";

  mymap->insert(std::pair<MyString, MyString>(key, value));

(For the complete code see http://www.hottis.de/boost/strings/. Thanks.)

What I'm wondering is: will the memory required for key and value be
freed automatically in the writing process (put.C)?
When I like to erase an element from the map, do I need to do more than
just calling mymap->erase(key)?
And finally when I'm done and like to remove the whole map, is more
required than segment.destroy<MyMap>("MyMap")? Will all the MyString's
in the map go too?

Furthermore: is it possible to use a map in shared memory as an
associative array and write:

  MyString value = (*mymap)[key];

It doesn't compile for me.

Thanks,
Wolfgang


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