AlignedAllocator.h
Go to the documentation of this file.
1 #ifndef MiscLib__ALIGNEDALLOCATOR_HEADER__
2 #define MiscLib__ALIGNEDALLOCATOR_HEADER__
3 #include <memory>
4 #include <malloc.h>
5 #include <xmmintrin.h>
6 #include <limits>
7 #ifdef max
8 #undef max
9 #endif
10 
11 namespace MiscLib
12 {
13 
14  enum { DefaultAlignment = sizeof(size_t) };
15 
16  template< class T, unsigned int Align = DefaultAlignment >
18  {
19  public:
20  typedef size_t size_type;
21  typedef ptrdiff_t difference_type;
22  typedef T* pointer;
23  typedef const T* const_pointer;
24  typedef T& reference;
25  typedef const T& const_reference;
26  typedef T value_type;
27  template< class U >
28  struct rebind
29  {
31  };
32 
33  AlignedAllocator() throw() {}
35  template< class U >
38  {
39  return &x;
40  }
42  {
43  return &x;
44  }
45  pointer allocate(size_type s, std::allocator_traits<std::allocator<void>>::const_void_pointer hint = 0)
46  {
47  return (T*)_mm_malloc(s * sizeof(T), Align);
48  }
50  {
51  _mm_free(p);
52  }
53  size_type max_size() const throw()
54  {
56  }
57  void construct(pointer p, const T& val)
58  {
59  new (static_cast< void* >(p)) T(val);
60  }
61  void destroy(pointer p)
62  {
63  p->~T();
64  }
65  template< class U >
67  {
68  return true;
69  }
70  template< class U >
71  bool operator==(const U&) const
72  {
73  return false;
74  }
75  template< class U >
77  {
78  return false;
79  }
80  template< class U >
81  bool operator!=(const U&) const
82  {
83  return true;
84  }
85  };
86 
87  template< unsigned int Align = sizeof(size_t) >
89  {
90  template< class T >
91  struct AllocType : public AlignedAllocator< T, Align > {};
92  };
93 
94 };
95 
96 #endif
MiscLib::AlignedAllocator::pointer
T * pointer
Definition: AlignedAllocator.h:22
MiscLib::MakeFixedAlignedAllocator
Definition: AlignedAllocator.h:88
MiscLib::AlignedAllocator::AlignedAllocator
AlignedAllocator()
Definition: AlignedAllocator.h:33
MiscLib::AlignedAllocator::address
const_pointer address(const_reference x) const
Definition: AlignedAllocator.h:41
MiscLib::AlignedAllocator::rebind
Definition: AlignedAllocator.h:28
MiscLib::AlignedAllocator::operator!=
bool operator!=(const AlignedAllocator< U, Align > &) const
Definition: AlignedAllocator.h:76
MiscLib::AlignedAllocator::allocate
pointer allocate(size_type s, std::allocator_traits< std::allocator< void >>::const_void_pointer hint=0)
Definition: AlignedAllocator.h:45
MiscLib::AlignedAllocator::address
pointer address(reference x) const
Definition: AlignedAllocator.h:37
MiscLib::AlignedAllocator::destroy
void destroy(pointer p)
Definition: AlignedAllocator.h:61
MiscLib::AlignedAllocator::max_size
size_type max_size() const
Definition: AlignedAllocator.h:53
MiscLib::AlignedAllocator::construct
void construct(pointer p, const T &val)
Definition: AlignedAllocator.h:57
MiscLib::AlignedAllocator::deallocate
void deallocate(pointer p, size_type)
Definition: AlignedAllocator.h:49
MiscLib::AlignedAllocator::rebind::other
AlignedAllocator< U, Align > other
Definition: AlignedAllocator.h:30
Point
Definition: PointCloud.h:21
MiscLib
Definition: AlignedAllocator.h:11
MiscLib::AlignedAllocator::operator==
bool operator==(const AlignedAllocator< U, Align > &) const
Definition: AlignedAllocator.h:66
max
T max(T t1, T t2)
Definition: gdiam.h:48
MiscLib::MakeFixedAlignedAllocator::AllocType
Definition: AlignedAllocator.h:91
MiscLib::AlignedAllocator::AlignedAllocator
AlignedAllocator(const AlignedAllocator< U, Align > &)
Definition: AlignedAllocator.h:36
MiscLib::AlignedAllocator::value_type
T value_type
Definition: AlignedAllocator.h:26
MiscLib::AlignedAllocator::const_pointer
const typedef T * const_pointer
Definition: AlignedAllocator.h:23
MiscLib::AlignedAllocator::operator!=
bool operator!=(const U &) const
Definition: AlignedAllocator.h:81
MiscLib::AlignedAllocator::AlignedAllocator
AlignedAllocator(const AlignedAllocator< T, Align > &)
Definition: AlignedAllocator.h:34
MiscLib::AlignedAllocator::const_reference
const typedef T & const_reference
Definition: AlignedAllocator.h:25
MiscLib::DefaultAlignment
@ DefaultAlignment
Definition: AlignedAllocator.h:14
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
MiscLib::AlignedAllocator::size_type
size_t size_type
Definition: AlignedAllocator.h:20
MiscLib::AlignedAllocator
Definition: AlignedAllocator.h:17
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:71
MiscLib::AlignedAllocator::difference_type
ptrdiff_t difference_type
Definition: AlignedAllocator.h:21
MiscLib::AlignedAllocator::reference
T & reference
Definition: AlignedAllocator.h:24