Boost logo

Boost Users :

From: Berenguer Blasi (bblasi_at_[hidden])
Date: 2006-07-13 06:17:23


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 <boost/shmem/named_shared_object.hpp>
#include <boost/shmem/containers/string.hpp>

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<char, fixed_named_shared_object::segment_manager>
      CharAllocator;
   typedef basic_string<char, std::char_traits<char>, CharAllocator>
      MyShmString;
   typedef allocator<MyShmString,
fixed_named_shared_object::segment_manager>
      StringAllocator;
   typedef vector<MyShmString, StringAllocator>
      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 <boost/shmem/named_shared_object.hpp>
#include <boost/shmem/containers/string.hpp>
#include <boost/shmem/allocators/allocator.hpp>

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<char, fixed_named_shared_object::segment_manager>
      CharAllocator;
   typedef basic_string<char, std::char_traits<char>, CharAllocator>
      MyShmString;
   typedef allocator<MyShmString,
fixed_named_shared_object::segment_manager>
      StringAllocator;
   typedef vector<MyShmString, StringAllocator>
      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;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net