Boost logo

Boost :

Subject: [boost] interprocess with unordered_map
From: Joel Young (jdy_at_[hidden])
Date: 2012-03-14 22:14:16



I've built a unordered_map in a memory mapped file. The map goes from:

typedef boost::interprocess::allocator<
> char_allocator_t;

typedef boost::interprocess::basic_string<

typedef std::pair< key_type, pay_type> val_type;

typedef boost::interprocess::allocator<
          boost::interprocess::managed_mapped_file::segment_manager> allocator_t;
typedef boost::unordered_map<
          allocator_t> map_type;

Everything works fine on creation. But when I later go to read from the map in
a different program where the mapped file is opened read only, I have to do
gymcrackery like:

      // A temporary string that allocates from the mapped file
      struct shm_clean { // cleanup shared memory on stack-unwind
        shm_clean() {
        ~shm_clean() {
      } cleaner;
stupid(boost::interprocess::create_only ,"StupidSharedMemory" ,500);
      key_type key_val(stupid.get_segment_manager());

to create a temporary to allow me to search since the maps find() method will
only take a key_type and interprocess::basic_string WILL NOT implicitly
construct from a std::string, nor will it implicitly construct from a char* to

Can the interprocess::basic_string be modified to allow these conversions?

I hate having to do:

key_val = "fruitcake";




Boost list run by bdawes at, gregod at, cpdaniel at, john at