wangzhengquan
2020-07-20 f85c9b875b060681b51f57b15074ba1c7c9f5636
queue/include/shm_allocator.h
@@ -9,7 +9,7 @@
template<class T> class SHMAllocator
template<class T> class SHM_STL_Allocator
{
public:
  typedef T               value_type;
@@ -21,10 +21,10 @@
  typedef ptrdiff_t       difference_type;
  SHMAllocator() {};
  ~SHMAllocator() {};
  template<class U> SHMAllocator(const SHMAllocator<U>& t) { };
  template<class U> struct rebind { typedef SHMAllocator<U> other; };
  SHM_STL_Allocator() {};
  ~SHM_STL_Allocator() {};
  template<class U> SHM_STL_Allocator(const SHM_STL_Allocator<U>& t) { };
  template<class U> struct rebind { typedef SHM_STL_Allocator<U> other; };
  pointer allocate(size_type n, const void* hint=0) {
//        fprintf(stderr, "allocate n=%u, hint= %p\n",n, hint);
@@ -63,12 +63,40 @@
};
class SHM_Allocator {
  public:
    static void *allocate (size_t size) {
       printf("shm_allocator malloc\n");
      return mm_malloc(size);
    }
    static void deallocate (void *ptr) {
      printf("shm_allocator free\n");
      return mm_free(ptr);
    }
};
class DM_Allocator {
  public:
    static void *allocate (size_t size) {
      printf("dm_allocator malloc\n");
      return malloc(size);
    }
    static void deallocate (void *ptr) {
      printf("dm_allocator free\n");
      return free(ptr);
    }
};
// template<class charT, class traits = char _traits<charT>,
// class Allocator = allocator<charT> >  
typedef std::basic_string<char, std::char_traits<char>, SHMAllocator<char> > shmstring;
typedef std::basic_string<char, std::char_traits<char>, SHM_STL_Allocator<char> > shmstring;
#endif