Hi Ion,
I have double checked that shm sizes and limits for my Fedora box are ok.
Thanks for the suggestion.
I've done some debugging and found the following:
1- You can create the segment ok
2- You can put data in it ok. I leave this process running in the
background.
3- I run a second process that reads the data from the shared:
3.1- The segment is opened ok (I noticed you don't check for errors the
return value of munmap)
3.2- The problem is at
segment.find<MyShmStringVector>("MyVector") from vectoGet (code below)
Returns a 0x0 pointer.
Why?
Line 630 of seg_manager.hpp sees 'it' as equal to 'index.end()'
Why?
When key_type for the index is created for some mysterious reason the values
'name' and name?s length are not stored correctly!!???
so index.find is comparing rubbish against the index. Therefore no
coincidence is found.
Notice you don?t have this problem with a non_fixed segment or if size is
66MB instead of 76MB. My shmem limit is 105MB.
I am completely lost!
code:
vectorGet.cpp
#include <vector>
#include
#include
int main ()
{
using namespace boost::shmem;
//Shared memory front-end that is able to construct objects
//associated with a c-string
fixed_named_shared_object segment;
//Open the memory segment at the specified address and initialize
resources
if(!segment.open("/MySharedMemory", //segment name
(void*)0x03000000)){ //mapping address
return -1;
}
//Typedefs
typedef allocator
CharAllocator;
typedef basic_string
MyShmString;
typedef allocator
StringAllocator;
typedef vector
MyShmStringVector;
//Find the vector using the c-string name
MyShmStringVector *myvector =
segment.find<MyShmStringVector>("MyVector").first;
//Use vector as you want
printf("%s\n",((*myvector)[0]).c_str());
// . . .
//When done, destroy and delete vector
//segment.destroy<MyVector>("MyVector");
printf("DONE\n");
}
----------------------------------
vectorPut.cpp
#include <vector>
#include
#include
#include
int main ()
{
using namespace boost::shmem;
//Shared memory front-end that is able to construct objects
//associated with a c-string
fixed_named_shared_object segment;
//Create the memory segment at the specified address and initialize
resources
segment.create("/MySharedMemory", //segment name
76000000 //segment size in bytes
,(void*)0x03000000); //mapping address
//Typedefs
typedef allocator
CharAllocator;
typedef basic_string
MyShmString;
typedef allocator
StringAllocator;
typedef vector
MyShmStringVector;
//Initialize shared memory STL-compatible allocator
CharAllocator charallocator (segment.get_segment_manager());
StringAllocator stringallocator(segment.get_segment_manager());
//Initialize vector
MyShmStringVector *myvector =
segment.construct<MyShmStringVector>("MyVector")
(stringallocator);//first ctor parameter
(void)myvector;
MyShmString str(charallocator);
str = "hola";
myvector->push_back(str);
while (1==1);
printf("DONE\n");
return 0;
}