vecmem 1.18.0
Loading...
Searching...
No Matches
allocator.hpp
1/*
2 * VecMem project, part of the ACTS project (R&D line)
3 *
4 * (c) 2021-2025 CERN for the benefit of the ACTS project
5 *
6 * Mozilla Public License Version 2.0
7 */
8
9#pragma once
10
11// Local include(s).
12#include "vecmem/memory/memory_resource.hpp"
13#include "vecmem/vecmem_core_export.hpp"
14
15// System include(s).
16#include <cstddef>
17
18namespace vecmem {
19
38public:
46 explicit allocator(memory_resource& mem);
47
59 void* allocate_bytes(std::size_t bytes,
60 std::size_t alignment = alignof(std::max_align_t));
61
75 void deallocate_bytes(void* p, std::size_t bytes,
76 std::size_t alignment = alignof(std::max_align_t));
77
91 template <typename T>
92 T* allocate_object(std::size_t n = 1);
93
105 template <typename T>
106 void deallocate_object(T* p, std::size_t n = 1);
107
119 template <typename T, typename... Args>
120 T* new_object(Args&&... args);
121
131 template <typename T>
132 void delete_object(T* p);
133
134private:
135 memory_resource& m_mem;
136
137}; // class allocator
138
139} // namespace vecmem
140
141// Include the implementation.
142#include "vecmem/memory/impl/allocator.ipp"
An allocator class that wraps a memory resource.
Definition allocator.hpp:37
T * allocate_object(std::size_t n=1)
Allocate space for (a number of) objects.
Definition allocator.ipp:15
T * new_object(Args &&... args)
Allocate and construct a new object.
Definition allocator.ipp:36
void deallocate_object(T *p, std::size_t n=1)
Deallocate space for (a number of) objects.
Definition allocator.ipp:26
void * allocate_bytes(std::size_t bytes, std::size_t alignment=alignof(std::max_align_t))
Allocate a given number of bytes.
Definition allocator.cpp:16
void delete_object(T *p)
Deconstruct and deallocate an object.
Definition allocator.ipp:54
void deallocate_bytes(void *p, std::size_t bytes, std::size_t alignment=alignof(std::max_align_t))
Deallocate a given number of bytes.
Definition allocator.cpp:29
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16