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-2020, 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;
41  using difference_type = std::ptrdiff_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)
size_t size(const MATRIXLIKE &m, const int dim)
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)
Aligned allocator that is compatible with C++11.
void * aligned_realloc(void *ptr, size_t size, size_t alignment)
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)
void deallocate(pointer p, size_type)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020