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
12namespace 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
39 {
40 }
41
45
46 template <class U>
50
53 {
54 return &x;
55 }
56
59 {
60 return &x;
61 }
62
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
77 max_size() const throw()
78 {
79 return std::numeric_limits<size_type>::max();
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
pointer allocate(size_type s, std::allocator_traits< std::allocator< void > >::const_void_pointer hint=0)
void deallocate(pointer p, size_type)
bool operator!=(const AlignedAllocator< U, Align > &) const
void construct(pointer p, const T &val)
pointer address(reference x) const
AlignedAllocator(const AlignedAllocator< U, Align > &)
const_pointer address(const_reference x) const
bool operator==(const AlignedAllocator< U, Align > &) const
bool operator==(const U &) const
bool operator!=(const U &) const
AlignedAllocator(const AlignedAllocator< T, Align > &)
This file offers overloads of toIce() and fromIce() functions for STL container types.
AlignedAllocator< U, Align > other