C++: Boost interprocess memory mapped file error -


i'm trying create memory mapped file using this answer, i'm getting compile errors. code:

namespace bi = boost::interprocess; std::string vecfile = "vector.dat"; bi::managed_mapped_file file_vec(bi::open_or_create,vecfile.c_str(), sizeof(struct rectangle) * data_size);  typedef bi::allocator<struct rectangle, bi::managed_mapped_file::segment_manager> rect_alloc; typedef std::vector<struct rectangle, rect_alloc>  myvec;  myvec * vecptr = file_vec.find_or_construct<myvec>("myvector")(file_vec.get_segment_manager());  vecptr->push_back(random_rectangle); 

the struct this:

struct rectangle{    rectangle(float *minarr, float *maxarr, int arr, int exp, int id){     this->arrival = arr;     this->expiry = exp;     this->id = id;     for(int i=0; < 2; i++){       min[i] = minarr[i];       max[i] = maxarr[i];     }    int arrival, expiry, id;   float min[2];   float max[2]; } 

the error is: compiler not deduce template argument '_ty*' 'boost::interprocess::offset_ptr'. doing wrong?

it looks okay me:

live on coliru

#include <boost/interprocess/managed_mapped_file.hpp> #include <vector>  namespace bi = boost::interprocess;  struct rectangle {     rectangle(float *minarr, float *maxarr, int arr, int exp, int id) {         this->arrival = arr;         this->expiry = exp;         this->id = id;         (int = 0; < 2; i++) {             min[i] = minarr[i];             max[i] = maxarr[i];         }     };      int arrival, expiry, id;     float min[2];     float max[2]; };  namespace shared {     using segment = bi::managed_mapped_file;     using mgr     = segment::segment_manager;      using alloc   = bi::allocator<rectangle, mgr>;     using vector  = std::vector<rectangle, alloc>; }  rectangle random_rectangle() {      float dummy[2] = { };     return { dummy, dummy, 0, 0, 0 };  }  int main() { #define data_size 10     std::string vecfile = "vector.dat";     shared::segment mmem(bi::open_or_create, vecfile.c_str(), (10u<<10) + sizeof(struct rectangle) * data_size);      shared::vector *vecptr = mmem.find_or_construct<shared::vector>("myvector")(mmem.get_segment_manager());      vecptr->push_back(random_rectangle()); } 

if doesn't compile above, please note versions of library , compiler. consider upgrading.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -