Boost logo

Boost Users :

Subject: [Boost-users] Do not understand about creating a vector of vector using Boost::interprocess libraries
From: 张国熙 (altriaex86_at_[hidden])
Date: 2014-08-15 08:49:51


Dear everyone,

I've just begun learning to use IPC in boost. Here I want to create a
vector of vector<std::complex<double>>, that is to say, a matrix of complex.

I read the section "containers of containers" in manual, and try to write
something as the following:

#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <complex>

typedef boost::interprocess::allocator<std::complex<double>,
boost::interprocess::managed_shared_memory::segment_manager>
ComplexAllocator;
typedef boost::interprocess::vector<std::complex<double>,ComplexAllocator>
ComplexVector;

typedef boost::interprocess::allocator<ComplexVector,
boost::interprocess::managed_shared_memory::segment_manager>
ComplexVectorAllocator;
typedef boost::interprocess::vector<ComplexVector,ComplexVectorAllocator>
ComplexMatrix;

int main ()
{
   struct shm_remove
   {
      shm_remove() {
boost::interprocess::shared_memory_object::remove("MySharedMemory"); }
      ~shm_remove(){
boost::interprocess::shared_memory_object::remove("MySharedMemory"); }
   } remover;
    boost::interprocess::create_only_t tag;
   boost::interprocess::managed_shared_memory segment(tag,
                                 "MySharedMemory",
                                 65536);
   const ComplexVectorAllocator alloc_inst (segment.get_segment_manager());

   ComplexMatrix *m =
      segment.construct<ComplexMatrix>
         ("M")(alloc_inst);
   m->resize(4);
   segment.destroy<ComplexMatrix>("M");
   return 0;
}

However, it could not compile. And the error message is too long for me to
understand. Is there anyone knowing how to fix this?

Best wishes,
Guoxi



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