Do not understand about creating a vector of vector using Boost::interprocess libraries
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
El 15/08/2014 14:49, 张国熙 escribió:
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.
m->resize(4);
A shared memory vector is not default constructible so you can't resize it without giving an argument. m->reserve(4); m->resize(4, (*m)[0]); should work. Best, Ion
participants (2)
-
Ion Gaztañaga
-
张国熙