1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <ros/ros.h>
// PCL specific includes
#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH
#include <fstream>
#include <iostream>
#include <map>
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/map.hpp>
#include <boost/interprocess/file_mapping.hpp>
#include <boost/interprocess/mapped_region.hpp>
using namespace boost::interprocess;
struct MyKey {
int d0, d1, d2, a0, b0, a1, b1, a2, b2;
bool operator < (const MyKey& o) const {
return std::tie(d0, d1, d2, a0, b0, a1, b1, a2, b2)
< std::tie(o.d0, o.d1, o.d2, o.a0, o.b0, o.a1, o.b1, o.a2, o.b2);
}
template<class Ar>
void serialize (Ar& ar, const unsigned int) {
ar & d0;
ar & d1;
// ditto
}
};
struct MyValue {
int p0, p1, p2;
template<class Ar>
void serialize(Ar& ar, const unsigned int) {
ar & p0;
ar & p1;
ar & p2;
//
}
};
int main (int argc, char** argv)
{
ros::init (argc, argv, "training");
ros::NodeHandle nh;
/*std::ofstream s("obj_pattern.bin");
boost::archive::text_oarchive oa(s);
std::map<MyKey, MyValue> pobj;
for(int i=0;i<1000000;i++) {
pobj.insert({{i, i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8}, {i, i+1, i+2}});
}
oa << pobj;*/
std::map<MyKey, MyValue> pobj;
file_mapping fm("obj_pattern.bin", read_only);
mapped_region region(fm, read_only);
MyKey * addr = (MyKey *)region.get_address();
auto it = addr->lower_bound({0, 1,2,3,4,5,6,7,8} );
if (it != end(pobj)) {
const MyKey& key = it->first;
const MyValue& value = it->second;
std::cout << "found: " << value.p0 << " " << value.p1 << " " << value.p2 << std::endl;
}
}
|