JayBeams  0.1
Another project to have fun coding.
allocator.hpp
Go to the documentation of this file.
1 #ifndef jb_fftw_allocator_hpp
2 #define jb_fftw_allocator_hpp
3 
4 #include <fftw3.h>
5 #include <limits>
6 #include <memory>
7 
8 namespace jb {
9 namespace fftw {
10 
11 /**
12  * Define an allocator based on fftw_malloc()/fftw_free()
13  *
14  * FFTW3 provides functions to allocate memory aligned to whatever
15  * requirements the vectorized instructions require.
16  */
17 template <typename T>
18 class allocator {
19 public:
20  typedef T value_type;
21  typedef value_type* pointer;
22  typedef value_type const* const_pointer;
23  typedef void* void_pointer;
24  typedef void const* const_void_pointer;
25  typedef std::size_t size_type;
26  typedef std::ptrdiff_t difference_type;
27  template <typename U>
28  struct rebind {
30  };
31 
32  pointer address(T& object) const {
33  return &object;
34  }
35  const_pointer address(T const& object) const {
36  return &object;
37  }
38  size_type max_size() const {
39  return std::numeric_limits<std::size_t>::max();
40  }
41  template <typename... Args>
42  void construct(pointer p, Args&&... args) {
43  new (static_cast<void*>(p)) T(std::forward<Args>(args)...);
44  }
45  void destroy(pointer p) {
46  p->~T();
47  }
48  pointer allocate(size_type count, const void* = 0) {
49  return reinterpret_cast<T*>(fftw_malloc(count * sizeof(T)));
50  }
51  void deallocate(pointer p, size_type count) {
52  fftw_free(static_cast<void*>(p));
53  }
54 
55  bool operator==(allocator const& rhs) const {
56  return true;
57  }
58  bool operator!=(allocator const& rhs) const {
59  return not(*this == rhs);
60  }
61 };
62 
63 } // namespace fftw
64 } // namespace jb
65 
66 #endif // jb_fftw_allocator_hpp
const_pointer address(T const &object) const
Definition: allocator.hpp:35
void destroy(pointer p)
Definition: allocator.hpp:45
bool operator==(allocator const &rhs) const
Definition: allocator.hpp:55
value_type const * const_pointer
Definition: allocator.hpp:22
void const * const_void_pointer
Definition: allocator.hpp:24
void deallocate(pointer p, size_type count)
Definition: allocator.hpp:51
std::size_t size_type
Definition: allocator.hpp:25
std::ptrdiff_t difference_type
Definition: allocator.hpp:26
pointer allocate(size_type count, const void *=0)
Definition: allocator.hpp:48
pointer address(T &object) const
Definition: allocator.hpp:32
Define an allocator based on fftw_malloc()/fftw_free()
Definition: allocator.hpp:18
void construct(pointer p, Args &&... args)
Definition: allocator.hpp:42
size_type max_size() const
Definition: allocator.hpp:38
bool operator!=(allocator const &rhs) const
Definition: allocator.hpp:58
value_type * pointer
Definition: allocator.hpp:21
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7