aligator
0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Toggle main menu visibility
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
7
namespace
aligator
{
8
15
class
polymorphic_allocator
16
:
public
std::pmr::polymorphic_allocator<std::byte> {
17
public
:
18
using
base
= std::pmr::polymorphic_allocator<std::byte>;
19
polymorphic_allocator
() noexcept
20
:
base
{std::pmr::get_default_resource()} {}
21
22
polymorphic_allocator
(
const
polymorphic_allocator
&other) =
default
;
23
24
template
<
typename
U>
25
polymorphic_allocator
(
26
const
std::pmr::polymorphic_allocator<U> &other) noexcept
27
:
base
{other} {}
28
29
polymorphic_allocator
(std::pmr::memory_resource *resource) noexcept
30
: std::pmr::polymorphic_allocator<std::byte>(resource) {}
31
32
template
<
typename
T>
33
[[nodiscard]] T *
allocate
(
size_t
n,
34
size_t
alignment = EIGEN_DEFAULT_ALIGN_BYTES) {
35
return
static_cast<
T *
>
(resource()->allocate(n *
sizeof
(T), alignment));
36
}
37
38
template
<
typename
T>
39
void
deallocate
(T *p,
size_t
n,
40
size_t
alignment = EIGEN_DEFAULT_ALIGN_BYTES) {
41
resource()->deallocate(p, n *
sizeof
(T), alignment);
42
}
43
44
[[nodiscard]]
void
*
45
allocate_bytes
(
size_t
num_bytes,
46
size_t
alignment = EIGEN_DEFAULT_ALIGN_BYTES) {
47
return
resource()->allocate(num_bytes, alignment);
48
}
49
50
void
deallocate_bytes
(
void
*p,
size_t
num_bytes,
51
size_t
alignment = EIGEN_DEFAULT_ALIGN_BYTES) {
52
resource()->deallocate(p, num_bytes, alignment);
53
}
54
};
55
56
}
// namespace aligator
57
58
template
<>
59
struct
std::allocator_traits<
aligator
::polymorphic_allocator>
60
: std::allocator_traits<aligator::polymorphic_allocator::base> {
61
using
allocator_type = aligator::polymorphic_allocator;
62
};
aligator::polymorphic_allocator::polymorphic_allocator
polymorphic_allocator(std::pmr::memory_resource *resource) noexcept
Definition
allocator.hpp:29
aligator::polymorphic_allocator::allocate_bytes
void * allocate_bytes(size_t num_bytes, size_t alignment=EIGEN_DEFAULT_ALIGN_BYTES)
Definition
allocator.hpp:45
aligator::polymorphic_allocator::base
std::pmr::polymorphic_allocator< std::byte > base
Definition
allocator.hpp:18
aligator::polymorphic_allocator::allocate
T * allocate(size_t n, size_t alignment=EIGEN_DEFAULT_ALIGN_BYTES)
Definition
allocator.hpp:33
aligator::polymorphic_allocator::polymorphic_allocator
polymorphic_allocator(const polymorphic_allocator &other)=default
aligator::polymorphic_allocator::polymorphic_allocator
polymorphic_allocator() noexcept
Definition
allocator.hpp:19
aligator::polymorphic_allocator::deallocate_bytes
void deallocate_bytes(void *p, size_t num_bytes, size_t alignment=EIGEN_DEFAULT_ALIGN_BYTES)
Definition
allocator.hpp:50
aligator::polymorphic_allocator::deallocate
void deallocate(T *p, size_t n, size_t alignment=EIGEN_DEFAULT_ALIGN_BYTES)
Definition
allocator.hpp:39
aligator::polymorphic_allocator::polymorphic_allocator
polymorphic_allocator(const std::pmr::polymorphic_allocator< U > &other) noexcept
Definition
allocator.hpp:25
aligator
Main package namespace.
Definition
action-model-wrap.hpp:14
include
aligator
core
allocator.hpp
Generated by
1.17.0