How to use interprocess communication to load the data into map

Hi, I am using boost interprocess library for loading the data into map <string, string> . And reading the same map with another program.I am benchmarking the code given on the following lilnk. http://www.boost.org/doc/libs/1_38_0/doc/html/interproc/quick_guide.html#int... #include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/containers/map.hpp> #include <boost/interprocess/allocators/allocator.hpp> #include <functional> #include <utility> int main () { using namespace boost::interprocess; //Shared memory front-end that is able to construct objects //associated with a c-string. Erase previous shared memory with the name //to be used and create the memory segment at the specified address and initialize resources shared_memory_object::remove("MySharedMemory"); try{ managed_shared_memory segment (create_only ,"MySharedMemory" //segment name ,65536); //segment size in bytes //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 float MappedType; typedef std::pair<const int, float> ValueType; //Alias an STL compatible allocator of for the map. //This allocator will allow to place containers //in managed shared memory segments typedef allocator<ValueType, managed_shared_memory::segment_manager> ShmemAllocator; //Alias a map of ints that uses the previous STL-like allocator. //Note that the third parameter argument is the ordering function //of the map, just like with std::map, used to compare the keys. typedef map<KeyType, MappedType, std::less<KeyType>, ShmemAllocator> MyMap; //Initialize the shared memory STL-compatible allocator ShmemAllocator alloc_inst (segment.get_segment_manager()); //Construct a shared memory map. //Note that the first parameter is the comparison function, //and the second one the allocator. //This the same signature as std::map's constructor taking an allocator MyMap *mymap = segment.construct<MyMap>("MyMap") //object name (std::less<int>() //first ctor parameter ,alloc_inst); //second ctor parameter //Insert data in the map for(int i = 0; i < 100; ++i){ mymap->insert(std::pair<const int, float>(i, (float)i)); } } catch(...){ shared_memory_object::remove("MySharedMemory"); throw; } shared_memory_object::remove("MySharedMemory"); return 0; } but getting the following errors. manish@user-desktop:~/Desktop$ g++ memorymap.cpp /tmp/ccmOQCB8.o: In function `boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t, char const*, boost::interprocess::mode_t)': memorymap.cpp:(.text._ZN5boost12interprocess20shared_memory_object19priv_open_or_createENS0_6detail13create_enum_tEPKcNS0_6mode_tE[boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t, char const*, boost::interprocess::mode_t)]+0x163): undefined reference to `shm_open' /tmp/ccmOQCB8.o: In function `boost::interprocess::detail::mutexattr_wrapper::mutexattr_wrapper(bool)': memorymap.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperC1Eb[boost::interprocess::detail::mutexattr_wrapper::mutexattr_wrapper(bool)]+0x14): undefined reference to `pthread_mutexattr_init' memorymap.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperC1Eb[boost::interprocess::detail::mutexattr_wrapper::mutexattr_wrapper(bool)]+0x2b): undefined reference to `pthread_mutexattr_setpshared' memorymap.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperC1Eb[boost::interprocess::detail::mutexattr_wrapper::mutexattr_wrapper(bool)]+0x4d): undefined reference to `pthread_mutexattr_settype' /tmp/ccmOQCB8.o: In function `boost::interprocess::detail::mutexattr_wrapper::~mutexattr_wrapper()': memorymap.cpp:(.text._ZN5boost12interprocess6detail17mutexattr_wrapperD1Ev[boost::interprocess::detail::mutexattr_wrapper::~mutexattr_wrapper()]+0xd): undefined reference to `pthread_mutexattr_destroy' /tmp/ccmOQCB8.o: In function `boost::interprocess::shared_memory_object::remove(char const*)': memorymap.cpp:(.text._ZN5boost12interprocess20shared_memory_object6removeEPKc[boost::interprocess::shared_memory_object::remove(char const*)]+0x33): undefined reference to `shm_unlink' collect2: ld returned 1 exit stats. What is the reason for this pblm? Thanks in advance. Regards Manish -- View this message in context: http://www.nabble.com/How-to-use-interprocess-communication-to-load-the-data... Sent from the Boost - Users mailing list archive at Nabble.com.

manish4gupta escribió:
What is the reason for this pblm? Thanks in advance.
Depending on your platform you need to link the appropriate threagin library. In recent linux systems, "-lrt" argument when compiling, but this depends on the plaform. Regards, Ion
Regards Manish

manish4gupta escribió:
What is the reason for this pblm? Thanks in advance.
This is also explained in the documentation: http://www.boost.org/doc/libs/1_40_0/doc/html/interprocess.html#interprocess... Best, Ion

Thankyou very much. Now i am able to compile the program with -lrt option. But how can i use the shared memory map. I have gone through the doc but still not clear. Please help. Regards Manish Ion Gaztañaga wrote:
manish4gupta escribió:
What is the reason for this pblm? Thanks in advance.
This is also explained in the documentation:
http://www.boost.org/doc/libs/1_40_0/doc/html/interprocess.html#interprocess...
Best,
Ion _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- View this message in context: http://www.nabble.com/How-to-use-interprocess-communication-to-load-the-data... Sent from the Boost - Users mailing list archive at Nabble.com.

manish4gupta escribió:
Thankyou very much. Now i am able to compile the program with -lrt option. But how can i use the shared memory map. I have gone through the doc but still not clear. Please help.
You have a full example in libs/interprocess/example/doc_map.cpp (this example is included in the documentation). I think it should be enough. Ion

Thanks, But this example only tell about loading the map into memory but how to use the map with another program still not clear.Can i get any example using the map. Regards Ion Gaztañaga wrote:
manish4gupta escribió:
Thankyou very much. Now i am able to compile the program with -lrt option. But how can i use the shared memory map. I have gone through the doc but still not clear. Please help.
You have a full example in libs/interprocess/example/doc_map.cpp (this example is included in the documentation). I think it should be enough.
Ion _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- View this message in context: http://www.nabble.com/How-to-use-interprocess-communication-to-load-the-data... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (2)
-
Ion Gaztañaga
-
manish4gupta