Coverage Report

Created: 2025-02-21 14:37

/root/bitcoin/src/support/allocators/pool.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2022 The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_SUPPORT_ALLOCATORS_POOL_H
6
#define BITCOIN_SUPPORT_ALLOCATORS_POOL_H
7
8
#include <array>
9
#include <cassert>
10
#include <cstddef>
11
#include <list>
12
#include <memory>
13
#include <new>
14
#include <type_traits>
15
#include <utility>
16
17
/**
18
 * A memory resource similar to std::pmr::unsynchronized_pool_resource, but
19
 * optimized for node-based containers. It has the following properties:
20
 *
21
 * * Owns the allocated memory and frees it on destruction, even when deallocate
22
 *   has not been called on the allocated blocks.
23
 *
24
 * * Consists of a number of pools, each one for a different block size.
25
 *   Each pool holds blocks of uniform size in a freelist.
26
 *
27
 * * Exhausting memory in a freelist causes a new allocation of a fixed size chunk.
28
 *   This chunk is used to carve out blocks.
29
 *
30
 * * Block sizes or alignments that can not be served by the pools are allocated
31
 *   and deallocated by operator new().
32
 *
33
 * PoolResource is not thread-safe. It is intended to be used by PoolAllocator.
34
 *
35
 * @tparam MAX_BLOCK_SIZE_BYTES Maximum size to allocate with the pool. If larger
36
 *         sizes are requested, allocation falls back to new().
37
 *
38
 * @tparam ALIGN_BYTES Required alignment for the allocations.
39
 *
40
 * An example: If you create a PoolResource<128, 8>(262144) and perform a bunch of
41
 * allocations and deallocate 2 blocks with size 8 bytes, and 3 blocks with size 16,
42
 * the members will look like this:
43
 *
44
 *     m_free_lists                         m_allocated_chunks
45
 *        ┌───┐                                ┌───┐  ┌────────────-------──────┐
46
 *        │   │  blocks                        │   ├─►│    262144 B             │
47
 *        │   │  ┌─────┐  ┌─────┐              └─┬─┘  └────────────-------──────┘
48
 *        │ 1 ├─►│ 8 B ├─►│ 8 B │                │
49
 *        │   │  └─────┘  └─────┘                :
50
 *        │   │                                  │
51
 *        │   │  ┌─────┐  ┌─────┐  ┌─────┐       ▼
52
 *        │ 2 ├─►│16 B ├─►│16 B ├─►│16 B │     ┌───┐  ┌─────────────────────────┐
53
 *        │   │  └─────┘  └─────┘  └─────┘     │   ├─►│          ▲              │ ▲
54
 *        │   │                                └───┘  └──────────┬──────────────┘ │
55
 *        │ . │                                                  │    m_available_memory_end
56
 *        │ . │                                         m_available_memory_it
57
 *        │ . │
58
 *        │   │
59
 *        │   │
60
 *        │16 │
61
 *        └───┘
62
 *
63
 * Here m_free_lists[1] holds the 2 blocks of size 8 bytes, and m_free_lists[2]
64
 * holds the 3 blocks of size 16. The blocks came from the data stored in the
65
 * m_allocated_chunks list. Each chunk has bytes 262144. The last chunk has still
66
 * some memory available for the blocks, and when m_available_memory_it is at the
67
 * end, a new chunk will be allocated and added to the list.
68
 */
69
template <std::size_t MAX_BLOCK_SIZE_BYTES, std::size_t ALIGN_BYTES>
70
class PoolResource final
71
{
72
    static_assert(ALIGN_BYTES > 0, "ALIGN_BYTES must be nonzero");
73
    static_assert((ALIGN_BYTES & (ALIGN_BYTES - 1)) == 0, "ALIGN_BYTES must be a power of two");
74
75
    /**
76
     * In-place linked list of the allocations, used for the freelist.
77
     */
78
    struct ListNode {
79
        ListNode* m_next;
80
81
0
        explicit ListNode(ListNode* next) : m_next(next) {}
Unexecuted instantiation: _ZN12PoolResourceILm144ELm8EE8ListNodeC2EPS1_
Unexecuted instantiation: _ZN12PoolResourceILm128ELm1EE8ListNodeC2EPS1_
Unexecuted instantiation: _ZN12PoolResourceILm128ELm2EE8ListNodeC2EPS1_
Unexecuted instantiation: _ZN12PoolResourceILm128ELm4EE8ListNodeC2EPS1_
Unexecuted instantiation: _ZN12PoolResourceILm128ELm8EE8ListNodeC2EPS1_
Unexecuted instantiation: _ZN12PoolResourceILm8ELm8EE8ListNodeC2EPS1_
Unexecuted instantiation: _ZN12PoolResourceILm16ELm16EE8ListNodeC2EPS1_
Unexecuted instantiation: _ZN12PoolResourceILm256ELm16EE8ListNodeC2EPS1_
Unexecuted instantiation: _ZN12PoolResourceILm256ELm64EE8ListNodeC2EPS1_
82
    };
83
    static_assert(std::is_trivially_destructible_v<ListNode>, "Make sure we don't need to manually call a destructor");
84
85
    /**
86
     * Internal alignment value. The larger of the requested ALIGN_BYTES and alignof(FreeList).
87
     */
88
    static constexpr std::size_t ELEM_ALIGN_BYTES = std::max(alignof(ListNode), ALIGN_BYTES);
89
    static_assert((ELEM_ALIGN_BYTES & (ELEM_ALIGN_BYTES - 1)) == 0, "ELEM_ALIGN_BYTES must be a power of two");
90
    static_assert(sizeof(ListNode) <= ELEM_ALIGN_BYTES, "Units of size ELEM_SIZE_ALIGN need to be able to store a ListNode");
91
    static_assert((MAX_BLOCK_SIZE_BYTES & (ELEM_ALIGN_BYTES - 1)) == 0, "MAX_BLOCK_SIZE_BYTES needs to be a multiple of the alignment.");
92
93
    /**
94
     * Size in bytes to allocate per chunk
95
     */
96
    const size_t m_chunk_size_bytes;
97
98
    /**
99
     * Contains all allocated pools of memory, used to free the data in the destructor.
100
     */
101
    std::list<std::byte*> m_allocated_chunks{};
102
103
    /**
104
     * Single linked lists of all data that came from deallocating.
105
     * m_free_lists[n] will serve blocks of size n*ELEM_ALIGN_BYTES.
106
     */
107
    std::array<ListNode*, MAX_BLOCK_SIZE_BYTES / ELEM_ALIGN_BYTES + 1> m_free_lists{};
108
109
    /**
110
     * Points to the beginning of available memory for carving out allocations.
111
     */
112
    std::byte* m_available_memory_it = nullptr;
113
114
    /**
115
     * Points to the end of available memory for carving out allocations.
116
     *
117
     * That member variable is redundant, and is always equal to `m_allocated_chunks.back() + m_chunk_size_bytes`
118
     * whenever it is accessed, but `m_available_memory_end` caches this for clarity and efficiency.
119
     */
120
    std::byte* m_available_memory_end = nullptr;
121
122
    /**
123
     * How many multiple of ELEM_ALIGN_BYTES are necessary to fit bytes. We use that result directly as an index
124
     * into m_free_lists. Round up for the special case when bytes==0.
125
     */
126
    [[nodiscard]] static constexpr std::size_t NumElemAlignBytes(std::size_t bytes)
127
0
    {
128
0
        return (bytes + ELEM_ALIGN_BYTES - 1) / ELEM_ALIGN_BYTES + (bytes == 0);
129
0
    }
Unexecuted instantiation: _ZN12PoolResourceILm144ELm8EE17NumElemAlignBytesEm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm1EE17NumElemAlignBytesEm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm2EE17NumElemAlignBytesEm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm4EE17NumElemAlignBytesEm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm8EE17NumElemAlignBytesEm
Unexecuted instantiation: _ZN12PoolResourceILm8ELm8EE17NumElemAlignBytesEm
Unexecuted instantiation: _ZN12PoolResourceILm16ELm16EE17NumElemAlignBytesEm
Unexecuted instantiation: _ZN12PoolResourceILm256ELm16EE17NumElemAlignBytesEm
Unexecuted instantiation: _ZN12PoolResourceILm256ELm64EE17NumElemAlignBytesEm
130
131
    /**
132
     * True when it is possible to make use of the freelist
133
     */
134
    [[nodiscard]] static constexpr bool IsFreeListUsable(std::size_t bytes, std::size_t alignment)
135
0
    {
136
0
        return alignment <= ELEM_ALIGN_BYTES && bytes <= MAX_BLOCK_SIZE_BYTES;
137
0
    }
Unexecuted instantiation: _ZN12PoolResourceILm144ELm8EE16IsFreeListUsableEmm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm1EE16IsFreeListUsableEmm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm2EE16IsFreeListUsableEmm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm4EE16IsFreeListUsableEmm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm8EE16IsFreeListUsableEmm
Unexecuted instantiation: _ZN12PoolResourceILm8ELm8EE16IsFreeListUsableEmm
Unexecuted instantiation: _ZN12PoolResourceILm16ELm16EE16IsFreeListUsableEmm
Unexecuted instantiation: _ZN12PoolResourceILm256ELm16EE16IsFreeListUsableEmm
Unexecuted instantiation: _ZN12PoolResourceILm256ELm64EE16IsFreeListUsableEmm
138
139
    /**
140
     * Replaces node with placement constructed ListNode that points to the previous node
141
     */
142
    void PlacementAddToList(void* p, ListNode*& node)
143
0
    {
144
0
        node = new (p) ListNode{node};
145
0
    }
Unexecuted instantiation: _ZN12PoolResourceILm144ELm8EE18PlacementAddToListEPvRPNS0_8ListNodeE
Unexecuted instantiation: _ZN12PoolResourceILm128ELm1EE18PlacementAddToListEPvRPNS0_8ListNodeE
Unexecuted instantiation: _ZN12PoolResourceILm128ELm2EE18PlacementAddToListEPvRPNS0_8ListNodeE
Unexecuted instantiation: _ZN12PoolResourceILm128ELm4EE18PlacementAddToListEPvRPNS0_8ListNodeE
Unexecuted instantiation: _ZN12PoolResourceILm128ELm8EE18PlacementAddToListEPvRPNS0_8ListNodeE
Unexecuted instantiation: _ZN12PoolResourceILm8ELm8EE18PlacementAddToListEPvRPNS0_8ListNodeE
Unexecuted instantiation: _ZN12PoolResourceILm16ELm16EE18PlacementAddToListEPvRPNS0_8ListNodeE
Unexecuted instantiation: _ZN12PoolResourceILm256ELm16EE18PlacementAddToListEPvRPNS0_8ListNodeE
Unexecuted instantiation: _ZN12PoolResourceILm256ELm64EE18PlacementAddToListEPvRPNS0_8ListNodeE
146
147
    /**
148
     * Allocate one full memory chunk which will be used to carve out allocations.
149
     * Also puts any leftover bytes into the freelist.
150
     *
151
     * Precondition: leftover bytes are either 0 or few enough to fit into a place in the freelist
152
     */
153
    void AllocateChunk()
154
0
    {
155
        // if there is still any available memory left, put it into the freelist.
156
0
        size_t remaining_available_bytes = std::distance(m_available_memory_it, m_available_memory_end);
157
0
        if (0 != remaining_available_bytes) {
158
0
            PlacementAddToList(m_available_memory_it, m_free_lists[remaining_available_bytes / ELEM_ALIGN_BYTES]);
159
0
        }
160
161
0
        void* storage = ::operator new (m_chunk_size_bytes, std::align_val_t{ELEM_ALIGN_BYTES});
162
0
        m_available_memory_it = new (storage) std::byte[m_chunk_size_bytes];
163
0
        m_available_memory_end = m_available_memory_it + m_chunk_size_bytes;
164
0
        m_allocated_chunks.emplace_back(m_available_memory_it);
165
0
    }
Unexecuted instantiation: _ZN12PoolResourceILm144ELm8EE13AllocateChunkEv
Unexecuted instantiation: _ZN12PoolResourceILm128ELm1EE13AllocateChunkEv
Unexecuted instantiation: _ZN12PoolResourceILm128ELm2EE13AllocateChunkEv
Unexecuted instantiation: _ZN12PoolResourceILm128ELm4EE13AllocateChunkEv
Unexecuted instantiation: _ZN12PoolResourceILm128ELm8EE13AllocateChunkEv
Unexecuted instantiation: _ZN12PoolResourceILm8ELm8EE13AllocateChunkEv
Unexecuted instantiation: _ZN12PoolResourceILm16ELm16EE13AllocateChunkEv
Unexecuted instantiation: _ZN12PoolResourceILm256ELm16EE13AllocateChunkEv
Unexecuted instantiation: _ZN12PoolResourceILm256ELm64EE13AllocateChunkEv
166
167
    /**
168
     * Access to internals for testing purpose only
169
     */
170
    friend class PoolResourceTester;
171
172
public:
173
    /**
174
     * Construct a new PoolResource object which allocates the first chunk.
175
     * chunk_size_bytes will be rounded up to next multiple of ELEM_ALIGN_BYTES.
176
     */
177
    explicit PoolResource(std::size_t chunk_size_bytes)
178
0
        : m_chunk_size_bytes(NumElemAlignBytes(chunk_size_bytes) * ELEM_ALIGN_BYTES)
179
0
    {
180
0
        assert(m_chunk_size_bytes >= MAX_BLOCK_SIZE_BYTES);
181
0
        AllocateChunk();
182
0
    }
Unexecuted instantiation: _ZN12PoolResourceILm144ELm8EEC2Em
Unexecuted instantiation: _ZN12PoolResourceILm128ELm1EEC2Em
Unexecuted instantiation: _ZN12PoolResourceILm128ELm2EEC2Em
Unexecuted instantiation: _ZN12PoolResourceILm128ELm4EEC2Em
Unexecuted instantiation: _ZN12PoolResourceILm128ELm8EEC2Em
Unexecuted instantiation: _ZN12PoolResourceILm8ELm8EEC2Em
Unexecuted instantiation: _ZN12PoolResourceILm16ELm16EEC2Em
Unexecuted instantiation: _ZN12PoolResourceILm256ELm16EEC2Em
Unexecuted instantiation: _ZN12PoolResourceILm256ELm64EEC2Em
183
184
    /**
185
     * Construct a new Pool Resource object, defaults to 2^18=262144 chunk size.
186
     */
187
0
    PoolResource() : PoolResource(262144) {}
188
189
    /**
190
     * Disable copy & move semantics, these are not supported for the resource.
191
     */
192
    PoolResource(const PoolResource&) = delete;
193
    PoolResource& operator=(const PoolResource&) = delete;
194
    PoolResource(PoolResource&&) = delete;
195
    PoolResource& operator=(PoolResource&&) = delete;
196
197
    /**
198
     * Deallocates all memory allocated associated with the memory resource.
199
     */
200
    ~PoolResource()
201
0
    {
202
0
        for (std::byte* chunk : m_allocated_chunks) {
203
0
            std::destroy(chunk, chunk + m_chunk_size_bytes);
204
0
            ::operator delete ((void*)chunk, std::align_val_t{ELEM_ALIGN_BYTES});
205
0
        }
206
0
    }
Unexecuted instantiation: _ZN12PoolResourceILm144ELm8EED2Ev
Unexecuted instantiation: _ZN12PoolResourceILm128ELm1EED2Ev
Unexecuted instantiation: _ZN12PoolResourceILm128ELm2EED2Ev
Unexecuted instantiation: _ZN12PoolResourceILm128ELm4EED2Ev
Unexecuted instantiation: _ZN12PoolResourceILm128ELm8EED2Ev
Unexecuted instantiation: _ZN12PoolResourceILm8ELm8EED2Ev
Unexecuted instantiation: _ZN12PoolResourceILm16ELm16EED2Ev
Unexecuted instantiation: _ZN12PoolResourceILm256ELm16EED2Ev
Unexecuted instantiation: _ZN12PoolResourceILm256ELm64EED2Ev
207
208
    /**
209
     * Allocates a block of bytes. If possible the freelist is used, otherwise allocation
210
     * is forwarded to ::operator new().
211
     */
212
    void* Allocate(std::size_t bytes, std::size_t alignment)
213
0
    {
214
0
        if (IsFreeListUsable(bytes, alignment)) {
215
0
            const std::size_t num_alignments = NumElemAlignBytes(bytes);
216
0
            if (nullptr != m_free_lists[num_alignments]) {
217
                // we've already got data in the pool's freelist, unlink one element and return the pointer
218
                // to the unlinked memory. Since FreeList is trivially destructible we can just treat it as
219
                // uninitialized memory.
220
0
                return std::exchange(m_free_lists[num_alignments], m_free_lists[num_alignments]->m_next);
221
0
            }
222
223
            // freelist is empty: get one allocation from allocated chunk memory.
224
0
            const std::ptrdiff_t round_bytes = static_cast<std::ptrdiff_t>(num_alignments * ELEM_ALIGN_BYTES);
225
0
            if (round_bytes > m_available_memory_end - m_available_memory_it) {
226
                // slow path, only happens when a new chunk needs to be allocated
227
0
                AllocateChunk();
228
0
            }
229
230
            // Make sure we use the right amount of bytes for that freelist (might be rounded up),
231
0
            return std::exchange(m_available_memory_it, m_available_memory_it + round_bytes);
232
0
        }
233
234
        // Can't use the pool => use operator new()
235
0
        return ::operator new (bytes, std::align_val_t{alignment});
236
0
    }
Unexecuted instantiation: _ZN12PoolResourceILm144ELm8EE8AllocateEmm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm1EE8AllocateEmm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm2EE8AllocateEmm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm4EE8AllocateEmm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm8EE8AllocateEmm
Unexecuted instantiation: _ZN12PoolResourceILm8ELm8EE8AllocateEmm
Unexecuted instantiation: _ZN12PoolResourceILm16ELm16EE8AllocateEmm
Unexecuted instantiation: _ZN12PoolResourceILm256ELm16EE8AllocateEmm
Unexecuted instantiation: _ZN12PoolResourceILm256ELm64EE8AllocateEmm
237
238
    /**
239
     * Returns a block to the freelists, or deletes the block when it did not come from the chunks.
240
     */
241
    void Deallocate(void* p, std::size_t bytes, std::size_t alignment) noexcept
242
0
    {
243
0
        if (IsFreeListUsable(bytes, alignment)) {
244
0
            const std::size_t num_alignments = NumElemAlignBytes(bytes);
245
            // put the memory block into the linked list. We can placement construct the FreeList
246
            // into the memory since we can be sure the alignment is correct.
247
0
            PlacementAddToList(p, m_free_lists[num_alignments]);
248
0
        } else {
249
            // Can't use the pool => forward deallocation to ::operator delete().
250
0
            ::operator delete (p, std::align_val_t{alignment});
251
0
        }
252
0
    }
Unexecuted instantiation: _ZN12PoolResourceILm144ELm8EE10DeallocateEPvmm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm1EE10DeallocateEPvmm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm2EE10DeallocateEPvmm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm4EE10DeallocateEPvmm
Unexecuted instantiation: _ZN12PoolResourceILm128ELm8EE10DeallocateEPvmm
Unexecuted instantiation: _ZN12PoolResourceILm8ELm8EE10DeallocateEPvmm
Unexecuted instantiation: _ZN12PoolResourceILm16ELm16EE10DeallocateEPvmm
Unexecuted instantiation: _ZN12PoolResourceILm256ELm16EE10DeallocateEPvmm
Unexecuted instantiation: _ZN12PoolResourceILm256ELm64EE10DeallocateEPvmm
253
254
    /**
255
     * Number of allocated chunks
256
     */
257
    [[nodiscard]] std::size_t NumAllocatedChunks() const
258
0
    {
259
0
        return m_allocated_chunks.size();
260
0
    }
261
262
    /**
263
     * Size in bytes to allocate per chunk, currently hardcoded to a fixed size.
264
     */
265
    [[nodiscard]] size_t ChunkSizeBytes() const
266
0
    {
267
0
        return m_chunk_size_bytes;
268
0
    }
Unexecuted instantiation: _ZNK12PoolResourceILm128ELm1EE14ChunkSizeBytesEv
Unexecuted instantiation: _ZNK12PoolResourceILm128ELm2EE14ChunkSizeBytesEv
Unexecuted instantiation: _ZNK12PoolResourceILm128ELm4EE14ChunkSizeBytesEv
Unexecuted instantiation: _ZNK12PoolResourceILm128ELm8EE14ChunkSizeBytesEv
Unexecuted instantiation: _ZNK12PoolResourceILm8ELm8EE14ChunkSizeBytesEv
Unexecuted instantiation: _ZNK12PoolResourceILm16ELm16EE14ChunkSizeBytesEv
Unexecuted instantiation: _ZNK12PoolResourceILm256ELm16EE14ChunkSizeBytesEv
Unexecuted instantiation: _ZNK12PoolResourceILm256ELm64EE14ChunkSizeBytesEv
Unexecuted instantiation: _ZNK12PoolResourceILm144ELm8EE14ChunkSizeBytesEv
269
};
270
271
272
/**
273
 * Forwards all allocations/deallocations to the PoolResource.
274
 */
275
template <class T, std::size_t MAX_BLOCK_SIZE_BYTES, std::size_t ALIGN_BYTES = alignof(T)>
276
class PoolAllocator
277
{
278
    PoolResource<MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>* m_resource;
279
280
    template <typename U, std::size_t M, std::size_t A>
281
    friend class PoolAllocator;
282
283
public:
284
    using value_type = T;
285
    using ResourceType = PoolResource<MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>;
286
287
    /**
288
     * Not explicit so we can easily construct it with the correct resource
289
     */
290
    PoolAllocator(ResourceType* resource) noexcept
291
0
        : m_resource(resource)
292
0
    {
293
0
    }
294
295
    PoolAllocator(const PoolAllocator& other) noexcept = default;
296
    PoolAllocator& operator=(const PoolAllocator& other) noexcept = default;
297
298
    template <class U>
299
    PoolAllocator(const PoolAllocator<U, MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>& other) noexcept
300
0
        : m_resource(other.resource())
301
0
    {
302
0
    }
Unexecuted instantiation: _ZN13PoolAllocatorIPNSt8__detail15_Hash_node_baseELm144ELm8EEC2INS0_10_Hash_nodeISt4pairIK9COutPoint16CCoinsCacheEntryELb0EEEEERKS_IT_Lm144ELm8EE
Unexecuted instantiation: _ZN13PoolAllocatorINSt8__detail10_Hash_nodeISt4pairIK9COutPoint16CCoinsCacheEntryELb0EEELm144ELm8EEC2IS6_EERKS_IT_Lm144ELm8EE
Unexecuted instantiation: _ZN13PoolAllocatorISt4pairIK9COutPoint16CCoinsCacheEntryELm144ELm8EEC2INSt8__detail10_Hash_nodeIS4_Lb0EEEEERKS_IT_Lm144ELm8EE
303
304
    /**
305
     * The rebind struct here is mandatory because we use non type template arguments for
306
     * PoolAllocator. See https://en.cppreference.com/w/cpp/named_req/Allocator#cite_note-2
307
     */
308
    template <typename U>
309
    struct rebind {
310
        using other = PoolAllocator<U, MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>;
311
    };
312
313
    /**
314
     * Forwards each call to the resource.
315
     */
316
    T* allocate(size_t n)
317
0
    {
318
0
        return static_cast<T*>(m_resource->Allocate(n * sizeof(T), alignof(T)));
319
0
    }
Unexecuted instantiation: _ZN13PoolAllocatorIPNSt8__detail15_Hash_node_baseELm144ELm8EE8allocateEm
Unexecuted instantiation: _ZN13PoolAllocatorINSt8__detail10_Hash_nodeISt4pairIK9COutPoint16CCoinsCacheEntryELb0EEELm144ELm8EE8allocateEm
320
321
    /**
322
     * Forwards each call to the resource.
323
     */
324
    void deallocate(T* p, size_t n) noexcept
325
0
    {
326
0
        m_resource->Deallocate(p, n * sizeof(T), alignof(T));
327
0
    }
Unexecuted instantiation: _ZN13PoolAllocatorINSt8__detail10_Hash_nodeISt4pairIK9COutPoint16CCoinsCacheEntryELb0EEELm144ELm8EE10deallocateEPS7_m
Unexecuted instantiation: _ZN13PoolAllocatorIPNSt8__detail15_Hash_node_baseELm144ELm8EE10deallocateEPS2_m
328
329
    ResourceType* resource() const noexcept
330
0
    {
331
0
        return m_resource;
332
0
    }
Unexecuted instantiation: _ZNK13PoolAllocatorINSt8__detail10_Hash_nodeISt4pairIK9COutPoint16CCoinsCacheEntryELb0EEELm144ELm8EE8resourceEv
Unexecuted instantiation: _ZNK13PoolAllocatorISt4pairIK9COutPoint16CCoinsCacheEntryELm144ELm8EE8resourceEv
333
};
334
335
template <class T1, class T2, std::size_t MAX_BLOCK_SIZE_BYTES, std::size_t ALIGN_BYTES>
336
bool operator==(const PoolAllocator<T1, MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>& a,
337
                const PoolAllocator<T2, MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>& b) noexcept
338
{
339
    return a.resource() == b.resource();
340
}
341
342
template <class T1, class T2, std::size_t MAX_BLOCK_SIZE_BYTES, std::size_t ALIGN_BYTES>
343
bool operator!=(const PoolAllocator<T1, MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>& a,
344
                const PoolAllocator<T2, MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>& b) noexcept
345
{
346
    return !(a == b);
347
}
348
349
#endif // BITCOIN_SUPPORT_ALLOCATORS_POOL_H