Skip to content

Instantly share code, notes, and snippets.

@bo0ts
Created October 25, 2012 12:46
Show Gist options
  • Save bo0ts/3952369 to your computer and use it in GitHub Desktop.
Save bo0ts/3952369 to your computer and use it in GitHub Desktop.
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <iostream>
using namespace boost::interprocess;
struct shm_remove {
shm_remove() {
shared_memory_object::remove("MySharedMemory");
}
~shm_remove() {
shared_memory_object::remove("MySharedMemory");
}
} remover;
managed_shared_memory segment(create_only,
"MySharedMemory", //segment name
65536);
template <typename _Tp>
class MyStdAllocator : public std::allocator<_Tp> {};
template<class T, class SegmentManager>
class MyBoostAllocator : public allocator<T, SegmentManager> {
public:
typedef SegmentManager segment_manager;
typedef typename SegmentManager::void_pointer void_pointer;
MyBoostAllocator(segment_manager *segment_mngr)
: allocator<T, SegmentManager>(segment_mngr) {
}
MyBoostAllocator()
: allocator<T, SegmentManager>(segment.get_segment_manager()) {
}
MyBoostAllocator(const allocator<T, SegmentManager> &other)
: allocator<T, SegmentManager>(other) {
}
template<class T2>
MyBoostAllocator(const allocator<T2, SegmentManager> &other)
: allocator<T, SegmentManager>(other) {
}
template<typename U>
struct rebind {
typedef MyBoostAllocator<U, SegmentManager> other;
};
};
typedef CGAL::Simple_cartesian<double> Kernel;
typedef std::allocator<int> StdAllocator;
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_3, CGAL::HalfedgeDS_default, StdAllocator> PolyhedronStd;
typedef allocator <int, managed_shared_memory::segment_manager> ShMemAllocator;
typedef MyBoostAllocator<int, managed_shared_memory::segment_manager> MyShMemAllocator;
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_3, CGAL::HalfedgeDS_default, ShMemAllocator > PolyhedronShMem;
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_3, CGAL::HalfedgeDS_default, MyShMemAllocator > MyPolyhedronShMem;
int main(int argc, char** argv) {
// PolyhedronStd p0; // it is working
PolyhedronShMem p1 = PolyhedronShMem(0, 0, 0, Kernel(), ShMemAllocator(segment.get_segment_manager())); // compilation error - impossible to pass constructor arguments
//MyPolyhedronShMem p2; // compilation error
//PolyhedronShMem p3(allocator_instance); //unfortunatelly no such constructor
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment