vecmem 1.14.0
Loading...
Searching...
No Matches
pool_memory_resource_impl.hpp
1/*
2 * VecMem project, part of the ACTS project (R&D line)
3 *
4 * (c) 2023 CERN for the benefit of the ACTS project
5 *
6 * Mozilla Public License Version 2.0
7 */
8#pragma once
9
10// Local include(s).
11#include "vecmem/memory/memory_resource.hpp"
12#include "vecmem/memory/pool_memory_resource.hpp"
13
14// System include(s).
15#include <functional>
16#include <vector>
17
18namespace vecmem::details {
19
22
23public:
25 pool_memory_resource_impl(memory_resource& upstream,
27
30
32 void* allocate(std::size_t bytes, std::size_t alignment);
33
35 void deallocate(void* ptr, std::size_t bytes, std::size_t alignment);
36
37private:
39 std::reference_wrapper<memory_resource> m_upstream;
42
44 struct chunk_descriptor {
46 std::size_t size = 0u;
48 void* pointer = nullptr;
49 };
50
52 struct oversized_block_descriptor {
54 std::size_t size = 0u;
56 std::size_t alignment = 0u;
58 void* pointer = nullptr;
59
61 bool operator<(const oversized_block_descriptor& other) const;
62 };
63
65 struct pool {
67 std::vector<void*> free_blocks;
68 std::size_t previous_allocated_count = 0u;
69 };
70
72 const std::size_t m_smallest_block_log2;
73
75 std::vector<pool> m_pools;
77 std::vector<chunk_descriptor> m_allocated;
80 std::vector<oversized_block_descriptor> m_cached_oversized;
83 std::vector<oversized_block_descriptor> m_oversized;
84
85}; // class pool_memory_resource_impl
86
87} // namespace vecmem::details
Implementation of vecmem::pool_memory_resource.
Definition pool_memory_resource_impl.hpp:21
void * allocate(std::size_t bytes, std::size_t alignment)
Allocate memory.
Definition pool_memory_resource_impl.cpp:96
void deallocate(void *ptr, std::size_t bytes, std::size_t alignment)
Deallocate memory.
Definition pool_memory_resource_impl.cpp:225
~pool_memory_resource_impl()
Destructor, freeing all allocations.
Definition pool_memory_resource_impl.cpp:82
Namespace for types that should not be used directly by clients.
Definition array.hpp:23
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35
Runtime options for vecmem::pool_memory_resource.
Definition pool_memory_resource.hpp:43