[shmem] problem retrieving objects from map

Hello,
I have a problem retrieving objects from a map placed in shared
memory. I have two processes:
proc#1: creates the shared memory, puts a map into it and populates it
with objects
proc#2: connects to the shared memory and tries to read out the
objects from the map
Whenever I try to read out the objects from the map, I get zeroes for
the internal members (a, b).
The class definition for the objects:
--------------------------------------------------
class ShmNode
{
private:
int a;
int b;
public:
ShmNode();
ShmNode(int newa, int newb);
~ShmNode();
void set(int newa, int newb);
int getA();
int getB();
};
--------------------------------------------------
I'm posting the source codes for the two programs. I removed the
synchronization stuff with semaphores for the sake of clarity:
Proc#1:
--------------------------------------------------
#include

The problem is you are storing pointers in the map, which are not in
the address space of proc#2. Check
http://ice.prohosting.com/newfunk/boost/libs/shmem/doc/html/shmem/limitation...
On 8/1/06, Pataki Szilard

Yeah, using pointers in that way is not something i've tried. Does the synchronization code you've removed stop the first program exiting before the second?

Hi!
Thanks for answering! Figured it out in the end...
-------------------------------------------
typedef std::pair<
const int,
ShmNode>
MyPair;
typedef boost::shmem::allocator <
MyPair,
boost::shmem::named_shared_object::segment_manager>
MyAlloc;
typedef boost::shmem::map<
const int,
ShmNode,
std::less<const int>,
MyAlloc>
MyMap;
(...)
ShmNode shmNode1(1, 2);
ShmNode shmNode2(3, 4);
ShmNode shmNode3(5, 6);
MyPair myPair1(1, shmNode1);
MyPair myPair2(2, shmNode2);
MyPair myPair3(3, shmNode3);
table->insert(myPair3);
table->insert(myPair1);
table->insert(myPair2);
-------------------------------------------
Still, can anybody explain what's the purpose of "comparator" and
"nodesAlloc" in the following piece of code? I found no documentation
whatsoever regarding this, and I managed to compile it by pure
accident. Why is there a need for a second comparator when one was
already defined for MyMap. Same story with the allocator...
-------------------------------------------
MyAlloc nodesAlloc(segment.get_segment_manager());
std::less<const int> comparator;
MyMap *table = segment.construct<MyMap>("table")(comparator, nodesAlloc);
-------------------------------------------
Regards,
Szilard
On 8/1/06, Adam Lewis
participants (3)
-
Adam Lewis
-
Jan Stetka
-
Pataki Szilard