AlignedAllocator.h
Go to the documentation of this file.
1 #ifndef MiscLib__ALIGNEDALLOCATOR_HEADER__
2 #define MiscLib__ALIGNEDALLOCATOR_HEADER__
3 #include <limits>
4 #include <memory>
5 
6 #include <malloc.h>
7 #include <xmmintrin.h>
8 #ifdef max
9 #undef max
10 #endif
11 
12 namespace MiscLib
13 {
14 
15  enum
16  {
17  DefaultAlignment = sizeof(size_t)
18  };
19 
20  template <class T, unsigned int Align = DefaultAlignment>
22  {
23  public:
24  typedef size_t size_type;
25  typedef ptrdiff_t difference_type;
26  typedef T* pointer;
27  typedef const T* const_pointer;
28  typedef T& reference;
29  typedef const T& const_reference;
30  typedef T value_type;
31 
32  template <class U>
33  struct rebind
34  {
36  };
37 
38  AlignedAllocator() throw()
39  {
40  }
41 
43  {
44  }
45 
46  template <class U>
48  {
49  }
50 
51  pointer
52  address(reference x) const
53  {
54  return &x;
55  }
56 
59  {
60  return &x;
61  }
62 
63  pointer
65  std::allocator_traits<std::allocator<void>>::const_void_pointer hint = 0)
66  {
67  return (T*)_mm_malloc(s * sizeof(T), Align);
68  }
69 
70  void
72  {
73  _mm_free(p);
74  }
75 
76  size_type
77  max_size() const throw()
78  {
80  }
81 
82  void
83  construct(pointer p, const T& val)
84  {
85  new (static_cast<void*>(p)) T(val);
86  }
87 
88  void
90  {
91  p->~T();
92  }
93 
94  template <class U>
95  bool
97  {
98  return true;
99  }
100 
101  template <class U>
102  bool
103  operator==(const U&) const
104  {
105  return false;
106  }
107 
108  template <class U>
109  bool
111  {
112  return false;
113  }
114 
115  template <class U>
116  bool
117  operator!=(const U&) const
118  {
119  return true;
120  }
121  };
122 
123  template <unsigned int Align = sizeof(size_t)>
125  {
126  template <class T>
127  struct AllocType : public AlignedAllocator<T, Align>
128  {
129  };
130  };
131 
132 }; // namespace MiscLib
133 
134 #endif
MiscLib::AlignedAllocator::pointer
T * pointer
Definition: AlignedAllocator.h:26
MiscLib::MakeFixedAlignedAllocator
Definition: AlignedAllocator.h:124
MiscLib::AlignedAllocator::AlignedAllocator
AlignedAllocator()
Definition: AlignedAllocator.h:38
MiscLib::AlignedAllocator::address
const_pointer address(const_reference x) const
Definition: AlignedAllocator.h:58
MiscLib::AlignedAllocator::rebind
Definition: AlignedAllocator.h:33
MiscLib::AlignedAllocator::operator!=
bool operator!=(const AlignedAllocator< U, Align > &) const
Definition: AlignedAllocator.h:110
MiscLib::AlignedAllocator::allocate
pointer allocate(size_type s, std::allocator_traits< std::allocator< void >>::const_void_pointer hint=0)
Definition: AlignedAllocator.h:64
MiscLib::AlignedAllocator::address
pointer address(reference x) const
Definition: AlignedAllocator.h:52
MiscLib::AlignedAllocator::destroy
void destroy(pointer p)
Definition: AlignedAllocator.h:89
MiscLib::AlignedAllocator::max_size
size_type max_size() const
Definition: AlignedAllocator.h:77
MiscLib::AlignedAllocator::construct
void construct(pointer p, const T &val)
Definition: AlignedAllocator.h:83
MiscLib::AlignedAllocator::deallocate
void deallocate(pointer p, size_type)
Definition: AlignedAllocator.h:71
Point
Definition: PointCloud.h:21
MiscLib
Definition: AlignedAllocator.h:12
MiscLib::AlignedAllocator::operator==
bool operator==(const AlignedAllocator< U, Align > &) const
Definition: AlignedAllocator.h:96
max
T max(T t1, T t2)
Definition: gdiam.h:51
MiscLib::MakeFixedAlignedAllocator::AllocType
Definition: AlignedAllocator.h:127
MiscLib::AlignedAllocator::AlignedAllocator
AlignedAllocator(const AlignedAllocator< U, Align > &)
Definition: AlignedAllocator.h:47
MiscLib::AlignedAllocator::value_type
T value_type
Definition: AlignedAllocator.h:30
MiscLib::AlignedAllocator::const_pointer
const typedef T * const_pointer
Definition: AlignedAllocator.h:27
MiscLib::AlignedAllocator::operator!=
bool operator!=(const U &) const
Definition: AlignedAllocator.h:117
MiscLib::AlignedAllocator::AlignedAllocator
AlignedAllocator(const AlignedAllocator< T, Align > &)
Definition: AlignedAllocator.h:42
MiscLib::AlignedAllocator::const_reference
const typedef T & const_reference
Definition: AlignedAllocator.h:29
MiscLib::AlignedAllocator::rebind::other
AlignedAllocator< U, Align > other
Definition: AlignedAllocator.h:35
MiscLib::DefaultAlignment
@ DefaultAlignment
Definition: AlignedAllocator.h:17
T
float T
Definition: UnscentedKalmanFilterTest.cpp:38
MiscLib::AlignedAllocator::size_type
size_t size_type
Definition: AlignedAllocator.h:24
MiscLib::AlignedAllocator
Definition: AlignedAllocator.h:21
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
MiscLib::AlignedAllocator::operator==
bool operator==(const U &) const
Definition: AlignedAllocator.h:103
MiscLib::AlignedAllocator::difference_type
ptrdiff_t difference_type
Definition: AlignedAllocator.h:25
MiscLib::AlignedAllocator::reference
T & reference
Definition: AlignedAllocator.h:28