MRPT  1.9.9
aligned_allocator.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
13 #include <memory>
14 #include <type_traits>
15 
16 namespace mrpt
17 {
18 void* aligned_malloc(size_t size, size_t alignment);
19 void* aligned_realloc(void* ptr, size_t size, size_t alignment);
20 void aligned_free(void* ptr);
21 /** Identical to aligned_malloc, but it zeroes the reserved memory block. */
22 inline void* aligned_calloc(size_t bytes, size_t alignment);
23 
24 /** Aligned allocator that is compatible with C++11.
25  * Default alignment can be 16 (default), 32 (if __AVX__ is defined) or 64
26  * (if __AVX2__ is defined).
27  * See: https://bitbucket.org/eigen/eigen/commits/f5b7700
28  *
29  * This was used (before May-2019) to provide custom STL aligned containers,
30  * but the new(n,m) addition to C++17 rendered this needless (at last!)
31  * See: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1409
32  *
33  * Anyway, this allocator class is left here just in case it is needed for
34  * something else.
35  */
36 template <class T, size_t AligmentBytes = MRPT_MAX_ALIGN_BYTES>
37 class aligned_allocator_cpp11 : public std::allocator<T>
38 {
39  public:
40  using size_type = std::size_t;
42  using pointer = T*;
43  using const_pointer = const T*;
44  using reference = T&;
45  using const_reference = const T&;
46  using value_type = T;
47 
48  template <class U>
49  struct rebind
50  {
52  };
53 
54  aligned_allocator_cpp11() : std::allocator<T>() {}
56  : std::allocator<T>(other)
57  {
58  }
59  template <class U>
61  : std::allocator<T>(other)
62  {
63  }
64  ~aligned_allocator_cpp11() = default;
65  pointer allocate(size_type num, const void* /*hint*/ = nullptr)
66  {
67  return static_cast<pointer>(
68  mrpt::aligned_malloc(num * sizeof(T), AligmentBytes));
69  }
71 };
72 
73 } // namespace mrpt
void aligned_free(void *ptr)
pointer allocate(size_type num, const void *=nullptr)
STL namespace.
aligned_allocator_cpp11(const aligned_allocator_cpp11< U > &other)
void * aligned_malloc(size_t size, size_t alignment)
GLuint GLuint num
Definition: glext.h:7397
Aligned allocator that is compatible with C++11.
void * aligned_realloc(void *ptr, size_t size, size_t alignment)
_W64 int ptrdiff_t
Definition: glew.h:136
void * aligned_calloc(size_t bytes, size_t alignment)
Identical to aligned_malloc, but it zeroes the reserved memory block.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
aligned_allocator_cpp11(const aligned_allocator_cpp11 &other)
GLsizeiptr size
Definition: glext.h:3934
void deallocate(pointer p, size_type)
GLfloat GLfloat p
Definition: glext.h:6398



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 4363012a5 Tue Nov 19 10:55:26 2019 +0100 at mar nov 19 11:00:13 CET 2019