$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: [boost] interprocess with unordered_map
From: Joel Young (jdy_at_[hidden])
Date: 2012-03-14 22:14:16
>> 
Folks,
I've built a unordered_map in a memory mapped file.  The map goes from:
typedef boost::interprocess::allocator<
        char,
        boost::interprocess::managed_mapped_file::segment_manager
  >                                         char_allocator_t;
typedef boost::interprocess::basic_string<
        char, 
        std::char_traits<char>,
        char_allocator_t
  >      
typedef std::pair<      key_type, pay_type> val_type;
typedef boost::interprocess::allocator<
          val_type, 
          boost::interprocess::managed_mapped_file::segment_manager> allocator_t;
  
typedef boost::unordered_map<
          key_type, 
          pay_type, 
          boost::hash<key_type>, 
          std::equal_to<key_type>, 
          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() { 
          boost::interprocess::shared_memory_object::remove("StupidSharedMemory");
        }
        ~shm_clean() {
          boost::interprocess::shared_memory_object::remove("StupidSharedMemory");
        }
      } cleaner;
      boost::interprocess::managed_shared_memory
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
itself.
Can the interprocess::basic_string be modified to allow these conversions?
I hate having to do:
key_val             = "fruitcake";
db.find(key_val);
Suggestions?
Thanks!
Joel