All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AlignedAllocator.h
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_ALIGNEDALLOCATOR_H_
36 #define _BLAZE_UTIL_ALIGNEDALLOCATOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/util/Memory.h>
44 #include <blaze/util/Null.h>
45 #include <blaze/util/Unused.h>
46 
47 
48 namespace blaze {
49 
50 //=================================================================================================
51 //
52 // CLASS DEFINITION
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
68 template< typename Type >
70 {
71  public:
72  //**Type definitions****************************************************************************
73  typedef Type ValueType;
74  typedef Type* Pointer;
75  typedef const Type* ConstPointer;
76  typedef Type& Reference;
77  typedef const Type& ConstReference;
78  typedef std::size_t SizeType;
79  typedef std::ptrdiff_t DifferenceType;
80 
81  // STL allocator requirements
83  typedef Pointer pointer;
85  typedef Reference reference;
87  typedef SizeType size_type;
89  //**********************************************************************************************
90 
91  //**rebind class definition*********************************************************************
94  template< typename Type2 >
95  struct rebind
96  {
98  };
99  //**********************************************************************************************
100 
101  //**Constructors********************************************************************************
104  explicit inline AlignedAllocator();
105 
106  template< typename Type2 >
107  inline AlignedAllocator( const AlignedAllocator<Type2>& );
109  //**********************************************************************************************
110 
111  //**Utility functions***************************************************************************
114  inline size_t maxSize() const;
115  inline Pointer address( Reference x ) const;
116  inline ConstPointer address( ConstReference x ) const;
118  //**********************************************************************************************
119 
120  //**Allocation functions************************************************************************
123  inline Pointer allocate ( size_t numObjects, const void* localityHint = NULL );
124  inline void deallocate( Pointer ptr, size_t numObjects );
126  //**********************************************************************************************
127 
128  //**Construction functions**********************************************************************
131  inline void construct( Pointer ptr, const Type& value );
132  inline void destroy ( Pointer ptr );
134  //**********************************************************************************************
135 };
136 //*************************************************************************************************
137 
138 
139 
140 
141 //=================================================================================================
142 //
143 // CONSTRUCTOR
144 //
145 //=================================================================================================
146 
147 //*************************************************************************************************
150 template< typename Type >
152 {}
153 //*************************************************************************************************
154 
155 
156 //*************************************************************************************************
161 template< typename Type >
162 template< typename Type2 >
164 {
165  UNUSED_PARAMETER( allocator );
166 }
167 //*************************************************************************************************
168 
169 
170 
171 
172 //=================================================================================================
173 //
174 // UTILITY FUNCTIONS
175 //
176 //=================================================================================================
177 
178 //*************************************************************************************************
183 template< typename Type >
184 inline size_t AlignedAllocator<Type>::maxSize() const
185 {
186  return size_t(-1) / sizeof( Type );
187 }
188 //*************************************************************************************************
189 
190 
191 //*************************************************************************************************
196 template< typename Type >
197 inline typename AlignedAllocator<Type>::Pointer
199 {
200  return &x;
201 }
202 //*************************************************************************************************
203 
204 
205 //*************************************************************************************************
210 template< typename Type >
213 {
214  return &x;
215 }
216 //*************************************************************************************************
217 
218 
219 
220 
221 //=================================================================================================
222 //
223 // ALLOCATION FUNCTIONS
224 //
225 //=================================================================================================
226 
227 //*************************************************************************************************
240 template< typename Type >
241 inline typename AlignedAllocator<Type>::Pointer
242  AlignedAllocator<Type>::allocate( size_t numObjects, const void* localityHint )
243 {
244  UNUSED_PARAMETER( localityHint );
245  return blaze::allocate<Type>( numObjects );
246 }
247 //*************************************************************************************************
248 
249 
250 //*************************************************************************************************
261 template< typename Type >
262 inline void AlignedAllocator<Type>::deallocate( Pointer ptr, size_t numObjects )
263 {
264  UNUSED_PARAMETER( numObjects );
265  blaze::deallocate( ptr );
266 }
267 //*************************************************************************************************
268 
269 
270 
271 
272 //=================================================================================================
273 //
274 // CONSTRUCTION FUNCTIONS
275 //
276 //=================================================================================================
277 
278 //*************************************************************************************************
288 template< typename Type >
290 {
291  ::new( ptr ) Type( value );
292 }
293 //*************************************************************************************************
294 
295 
296 //*************************************************************************************************
305 template< typename Type >
307 {
308  ptr->~Type();
309 }
310 //*************************************************************************************************
311 
312 
313 
314 
315 //=================================================================================================
316 //
317 // GLOBAL OPERATORS
318 //
319 //=================================================================================================
320 
321 //*************************************************************************************************
324 template< typename T1, typename T2 >
325 inline bool operator==( const AlignedAllocator<T1>& lhs, const AlignedAllocator<T2>& rhs );
326 
327 template< typename T1, typename T2 >
328 inline bool operator!=( const AlignedAllocator<T1>& lhs, const AlignedAllocator<T2>& rhs );
330 //*************************************************************************************************
331 
332 
333 //*************************************************************************************************
340 template< typename T1 // Type of the left-hand side aligned allocator
341  , typename T2 > // Type of the right-hand side aligned allocator
342 inline bool operator==( const AlignedAllocator<T1>& lhs, const AlignedAllocator<T2>& rhs )
343 {
344  UNUSED_PARAMETER( lhs, rhs );
345  return true;
346 }
347 //*************************************************************************************************
348 
349 
350 //*************************************************************************************************
357 template< typename T1 // Type of the left-hand side aligned allocator
358  , typename T2 > // Type of the right-hand side aligned allocator
359 inline bool operator!=( const AlignedAllocator<T1>& lhs, const AlignedAllocator<T2>& rhs )
360 {
361  UNUSED_PARAMETER( lhs, rhs );
362  return false;
363 }
364 //*************************************************************************************************
365 
366 } // namespace blaze
367 
368 #endif
Type ValueType
Type of the allocated values.
Definition: AlignedAllocator.h:73
SizeType size_type
Size type of the aligned allocator.
Definition: AlignedAllocator.h:87
Header file for the UNUSED_PARAMETER function template.
size_t maxSize() const
Returns the maximum possible number of elements that can be allocated together.
Definition: AlignedAllocator.h:184
const blaze::Null NULL
Global NULL pointer.This instance of the Null class replaces the NULL macro to ensure a type-safe NUL...
Definition: Null.h:300
Header file for a safe C++ NULL pointer implementation.
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:84
Type * Pointer
Type of a pointer to the allocated values.
Definition: AlignedAllocator.h:74
AlignedAllocator< Type2 > other
Type of the other allocator.
Definition: AlignedAllocator.h:97
Header file for memory allocation and deallocation functionality.
void deallocate(T *address)
Deallocation of memory.
Definition: Memory.h:115
const Type & ConstReference
Type of a reference-to-const to the allocated values.
Definition: AlignedAllocator.h:77
std::ptrdiff_t DifferenceType
Difference type of the aligned allocator.
Definition: AlignedAllocator.h:79
const Type * ConstPointer
Type of a pointer-to-const to the allocated values.
Definition: AlignedAllocator.h:75
Pointer allocate(size_t numObjects, const void *localityHint=NULL)
Allocates aligned memory for the specified number of objects.
Definition: AlignedAllocator.h:242
ValueType value_type
Type of the allocated values.
Definition: AlignedAllocator.h:82
void construct(Pointer ptr, const Type &value)
Constructs an object of type Type at the specified memory location.
Definition: AlignedAllocator.h:289
DifferenceType difference_type
Difference type of the aligned allocator.
Definition: AlignedAllocator.h:88
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2410
Allocator for type-specific aligned memory.The AlignedAllocator class template represents an implemen...
Definition: AlignedAllocator.h:69
ConstReference const_reference
Type of a reference-to-const to the allocated values.
Definition: AlignedAllocator.h:86
std::size_t SizeType
Size type of the aligned allocator.
Definition: AlignedAllocator.h:78
Pointer pointer
Type of a pointer to the allocated values.
Definition: AlignedAllocator.h:83
void deallocate(Pointer ptr, size_t numObjects)
Deallocation of memory.
Definition: AlignedAllocator.h:262
ConstPointer const_pointer
Type of a pointer-to-const to the allocated values.
Definition: AlignedAllocator.h:84
Pointer address(Reference x) const
Returns the address of the given element.
Definition: AlignedAllocator.h:198
AlignedAllocator()
The default constructor for AlignedAllocator.
Definition: AlignedAllocator.h:151
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
Reference reference
Type of a reference to the allocated values.
Definition: AlignedAllocator.h:85
void destroy(Pointer ptr)
Destroys the object of type Type at the specified memory location.
Definition: AlignedAllocator.h:306
Size type of the Blaze library.
Type & Reference
Type of a reference to the allocated values.
Definition: AlignedAllocator.h:76
Implementation of the AlignedAllocator rebind mechanism.
Definition: AlignedAllocator.h:95