Blender
V4.5
source
blender
blenlib
BLI_pool.hh
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
16
#pragma once
17
18
#include "
BLI_stack.hh
"
19
#include "
BLI_utility_mixins.hh
"
20
#include "
BLI_vector.hh
"
21
22
namespace
blender
{
23
24
template
<
typename
T,
int
64_t ChunkLen = 64>
class
Pool
:
NonCopyable
{
25
private
:
26
using
Chunk
=
TypedBuffer<T, ChunkLen>
;
27
29
Vector<std::unique_ptr<Chunk>
> values_;
33
Stack<T *, 0>
free_list_;
34
35
public
:
36
~Pool
()
37
{
38
/* All elements need to be freed before freeing the pool. */
39
BLI_assert
(this->
size
() == 0);
40
}
41
45
template
<
typename
... ForwardT> T &
construct
(ForwardT &&...
value
)
46
{
47
if
(free_list_.
is_empty
()) {
48
values_.
append
(std::make_unique<Chunk>());
49
T *chunk_start = values_.
last
()->ptr();
50
for
(
auto
i :
IndexRange
(ChunkLen)) {
51
free_list_.
push
(chunk_start + i);
52
}
53
}
54
T *
ptr
= free_list_.
pop
();
55
new
(
ptr
)
T
(std::forward<ForwardT>(
value
)...);
56
return
*
ptr
;
57
}
58
63
void
destruct
(T &
value
)
64
{
65
value
.~T();
66
free_list_.
push
(&
value
);
67
}
68
72
int64_t
size
()
const
73
{
74
return
values_.
size
() * ChunkLen - free_list_.
size
();
75
}
76
80
bool
is_empty
()
const
81
{
82
return
this->
size
() == 0;
83
}
84
};
85
86
}
// namespace blender
BLI_assert
#define BLI_assert(a)
Definition
BLI_assert.h:46
BLI_stack.hh
BLI_utility_mixins.hh
BLI_vector.hh
blender::IndexRange
Definition
BLI_index_range.hh:50
blender::NonCopyable
Definition
BLI_utility_mixins.hh:16
blender::Pool
Definition
BLI_pool.hh:24
blender::Pool::~Pool
~Pool()
Definition
BLI_pool.hh:36
blender::Pool::destruct
void destruct(T &value)
Definition
BLI_pool.hh:63
blender::Pool::size
int64_t size() const
Definition
BLI_pool.hh:72
blender::Pool::construct
T & construct(ForwardT &&...value)
Definition
BLI_pool.hh:45
blender::Pool::is_empty
bool is_empty() const
Definition
BLI_pool.hh:80
blender::Stack
Definition
BLI_stack.hh:70
blender::Stack::is_empty
bool is_empty() const
Definition
BLI_stack.hh:308
blender::Stack::pop
T pop()
Definition
BLI_stack.hh:242
blender::Stack::push
void push(const T &value)
Definition
BLI_stack.hh:213
blender::Stack::size
int64_t size() const
Definition
BLI_stack.hh:316
blender::TypedBuffer
Definition
BLI_memory_utils.hh:155
blender::Vector
Definition
BLI_vector.hh:76
blender::Vector::size
int64_t size() const
Definition
BLI_vector.hh:771
blender::Vector::append
void append(const T &value)
Definition
BLI_vector.hh:489
blender::Vector::last
const T & last(const int64_t n=0) const
Definition
BLI_vector.hh:740
ptr
PointerRNA ptr
Definition
geometry_nodes_caller_ui.cc:49
T
#define T
Definition
mball_tessellate.cc:274
blender
Definition
ANIM_action.hh:36
int64_t
__int64 int64_t
Definition
stdint.h:89
value
T value
Definition
usd_reader_camera.cc:34
Generated on Fri Apr 3 2026 06:33:18 for Blender by
doxygen
1.11.0