vecmem 1.18.0
Loading...
Searching...
No Matches
memory_resource_impl.hpp
1/* VecMem project, part of the ACTS project (R&D line)
2 *
3 * (c) 2023-2025 CERN for the benefit of the ACTS project
4 *
5 * Mozilla Public License Version 2.0
6 */
7
8#pragma once
9
10// Local include(s).
11#include "vecmem/utils/debug.hpp"
12
13// System include(s).
14#include <cassert>
15#include <stdexcept>
16
23#define VECMEM_MEMORY_RESOURCE_PIMPL_IMPL(CLASSNAME) \
24 CLASSNAME::CLASSNAME(CLASSNAME&&) noexcept = default; \
25 CLASSNAME::~CLASSNAME() = default; \
26 CLASSNAME& CLASSNAME::operator=(CLASSNAME&&) noexcept = default; \
27 void* CLASSNAME::do_allocate(std::size_t size, std::size_t alignment) { \
28 if (size == 0) { \
29 throw std::bad_alloc(); \
30 } \
31 assert(m_impl); \
32 void* ptr = m_impl->allocate(size, alignment); \
33 VECMEM_DEBUG_MSG(2, "Allocated %lu bytes at %p", size, ptr); \
34 return ptr; \
35 } \
36 void CLASSNAME::do_deallocate(void* ptr, std::size_t size, \
37 std::size_t alignment) { \
38 assert(ptr != nullptr); \
39 if (size == 0u) { \
40 return; \
41 } \
42 VECMEM_DEBUG_MSG(2, "De-allocating memory at %p", ptr); \
43 assert(m_impl); \
44 m_impl->deallocate(ptr, size, alignment); \
45 }