Announcement

Collapse
No announcement yet.

Boost managed shared memory und map

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Boost managed shared memory und map

    Hallo,
    ich habe folgenden Problem in meinem 1. Projekt lege ich eine shared map an.
    genau wie unter: http://www.systomath.com/include/Boo...terprocess_map
    So:
    Code:
    ...
    
    shared_memory_object::remove("shared_memory");
    
    	managed_shared_memory mshm_obj(create_only,"shared_memory",5120);
    	
            //Note that map<Key, MappedType>'s value_type is 
            //  std::pair<const Key,  MappedType>,
            //so the allocator must allocate that pair.
        typedef int    KeyType;
        typedef package  MappedType;
        typedef std::pair<const int, package> ValueType;
    	
        //Alias an STL compatible allocator of for the map.
        //This allocator will allow to place containers
        //in managed shared memory segments
       	typedef boost::interprocess::allocator<ValueType,
              managed_shared_memory::segment_manager>	ShmAllocator;
    	typedef boost::interprocess::map<KeyType, MappedType,
             std::less<KeyType>, ShmAllocator> packageMap;
    	//Initialize the shared memory STL-compatible allocator
    	///////////////////////////////////	
    	ShmAllocator alloc_inst (mshm_obj.get_segment_manager());
    
    	//Construct a shared memory map.
    	packageMap *myPackageMap = mshm_obj.construct<packageMap>
             ("PackageMap")(std::less<int>(),alloc_inst);
    
    
    
    /*	package temp_test_pack;
    	temp_test_pack.LIID = 1;
    
         //Insert data in the map
        for(int i = 0; i < 10; ++i)
    	{
    	    myPackageMap->insert(std::pair<const int, package>(i, temp_test_pack));
        }*/
    
    /*	packageMap::iterator it;
    	for (it = myPackageMap->begin(); it != myPackageMap->end(); it++)
    	{
    		cout << it->first << endl;
    	}
    */
    den Kommentar oben will ich nun in ein anderen Prozess "verlegen". Also ich will hier die shared map anlegen und mit einem anderen Prozess füllen. und mit dem Prozess oben wieder ausgeben.

    Mein problem ist nur wie kann ich auf die Map von einem anderen Prozess zugreifen??
    Bisher habe ich das:
    Code:
    try{
    //Open already created shared memory object.
    managed_shared_memory mshm_obj (open_only, "shared_memory");
    typedef int    KeyType;
    typedef package  MappedType;
    typedef std::pair<const int, package> ValueType;
    //Alias an STL compatible allocator of for the map.
    //This allocator will allow to place containers
    //in managed shared memory segments
    typedef boost::interprocess::allocator<ValueType, memory::segment_manager>	ShmAllocator;
    //typedef boost::interprocess::map<KeyType, MappedType, std::less<KeyType>, ShmAllocator> packageMap;
    
    //Initialize the shared memory STL-compatible allocator
    ///////////////////////////////////
    ShmAllocator alloc_inst (mshm_obj.get_segment_manager());
    soweit so gut. Aber woher bekomme ich nun einen verweis auf die Map oder auf den Inhalt von shared Memory??

    Bzw. wie kann ich die Map auslesen und ggf. füllen.
    Ich hab schon die beispiele von Boost und highscore durch gearbeitet ich komme aber nicht drauf.

    Gruß und Danke vorab

  • #2
    http://www.c-plusplus.de/forum/viewt...s-1963752.html

    geschlossen
    Christian

    Comment

    Working...
    X