aligator  0.15.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
allocator.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include <Eigen/Core>
5#include <memory_resource>
6
7namespace aligator {
8
9using byte_t = std::byte;
10
17class polymorphic_allocator : public std::pmr::polymorphic_allocator<byte_t> {
18public:
19 using base = std::pmr::polymorphic_allocator<byte_t>;
21 : base{std::pmr::get_default_resource()} {}
22
24
25 template <typename U>
27 const std::pmr::polymorphic_allocator<U> &other) noexcept
28 : base{other} {}
29
30 polymorphic_allocator(std::pmr::memory_resource *resource) noexcept
31 : std::pmr::polymorphic_allocator<byte_t>(resource) {}
32
33 template <typename T>
34 [[nodiscard]] T *allocate(size_t n,
35 size_t alignment = EIGEN_DEFAULT_ALIGN_BYTES) {
36 return static_cast<T *>(resource()->allocate(n * sizeof(T), alignment));
37 }
38
39 template <typename T>
40 void deallocate(T *p, size_t n,
41 size_t alignment = EIGEN_DEFAULT_ALIGN_BYTES) {
42 resource()->deallocate(p, n * sizeof(T), alignment);
43 }
44
45 [[nodiscard]] void *
46 allocate_bytes(size_t num_bytes,
47 size_t alignment = EIGEN_DEFAULT_ALIGN_BYTES) {
48 return resource()->allocate(num_bytes, alignment);
49 }
50
51 void deallocate_bytes(void *p, size_t num_bytes,
52 size_t alignment = EIGEN_DEFAULT_ALIGN_BYTES) {
53 resource()->deallocate(p, num_bytes, alignment);
54 }
55};
56
57} // namespace aligator
58
59template <>
60struct std::allocator_traits<aligator::polymorphic_allocator>
61 : std::allocator_traits<aligator::polymorphic_allocator::base> {
62 using allocator_type = aligator::polymorphic_allocator;
63};
polymorphic_allocator(std::pmr::memory_resource *resource) noexcept
Definition allocator.hpp:30
void * allocate_bytes(size_t num_bytes, size_t alignment=EIGEN_DEFAULT_ALIGN_BYTES)
Definition allocator.hpp:46
T * allocate(size_t n, size_t alignment=EIGEN_DEFAULT_ALIGN_BYTES)
Definition allocator.hpp:34
std::pmr::polymorphic_allocator< byte_t > base
Definition allocator.hpp:19
polymorphic_allocator(const polymorphic_allocator &other)=default
void deallocate_bytes(void *p, size_t num_bytes, size_t alignment=EIGEN_DEFAULT_ALIGN_BYTES)
Definition allocator.hpp:51
void deallocate(T *p, size_t n, size_t alignment=EIGEN_DEFAULT_ALIGN_BYTES)
Definition allocator.hpp:40
polymorphic_allocator(const std::pmr::polymorphic_allocator< U > &other) noexcept
Definition allocator.hpp:26
Main package namespace.
std::byte byte_t
Definition allocator.hpp:9