I am trying to create unordered_map in shared memory. I use a dispenser for the purpose of the server.
Code
void *addr; void *pool; int shmid; template<class T> class MyPoolAlloc { private: public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T* pointer; typedef const T* const_pointer; typedef T& reference; typedef const T& const_reference; typedef T value_type; template<class X> struct rebind { typedef MyPoolAlloc<X> other; }; MyPoolAlloc() throw() { } MyPoolAlloc(const MyPoolAlloc&) throw() { } template<class X> MyPoolAlloc(const MyPoolAlloc<X>&) throw() { } ~MyPoolAlloc() throw() { } pointer address(reference __x) const { return &__x; } const_pointer address(const_reference __x) const { return &__x; } pointer allocate(size_type __n, const void * hint = 0) { pointer tmp = static_cast<T*>(addr); addr = (void*)((char*)addr + __n); return tmp; } void deallocate(pointer __p, size_type __n) {
I allocate memory for the card at the shared memory address. And I believe that the allocate function of the allocator () class will be used for elements. But I canβt understand how to use the allocate function to allocate memory for map elements. I get an arithmetic exception on the line where I am trying to insert on a card.
Can someone help to understand what a memory layout should look like?
Thanks.
source share