21#ifndef GF_SPATIAL_BLOCK_ALLOCATOR_H
22#define GF_SPATIAL_BLOCK_ALLOCATOR_H
28#ifndef DOXYGEN_SHOULD_SKIP_THIS
38 constexpr std::size_t
NullIndex =
static_cast<std::size_t
>(-1);
65 index = m_firstFreeBlock;
66 m_firstFreeBlock = m_blocks[index].next;
69 index = m_blocks.size();
70 m_blocks.push_back(
Block());
73 assert(index < m_blocks.size());
74 assert(m_blocks[index].next ==
NullIndex);
88 assert(index < m_blocks.size());
89 m_blocks[index].next = m_firstFreeBlock;
90 m_firstFreeBlock = index;
100 assert(index < m_blocks.size());
101 assert(m_blocks[index].next ==
NullIndex);
102 return m_blocks[index].data;
111 assert(index < m_blocks.size());
112 assert(m_blocks[index].next ==
NullIndex);
113 return m_blocks[index].data;
139 std::size_t m_firstFreeBlock;
140 std::vector<Block> m_blocks;
141 std::size_t m_allocated;
145#ifndef DOXYGEN_SHOULD_SKIP_THIS
An allocator of objects referenced by an index.
Definition: BlockAllocator.h:45
std::size_t allocate()
Allocate an object.
Definition: BlockAllocator.h:61
void dispose(std::size_t index)
Deallocate the object at the given index.
Definition: BlockAllocator.h:87
std::size_t getAllocated() const
Get the number of allocated objects.
Definition: BlockAllocator.h:129
T & operator[](std::size_t index)
Access the object at a given index.
Definition: BlockAllocator.h:99
void clear()
Remove all objects at once.
Definition: BlockAllocator.h:119
BlockAllocator()
Default constructor.
Definition: BlockAllocator.h:50
const T & operator[](std::size_t index) const
Access the object at a given index.
Definition: BlockAllocator.h:110
constexpr std::size_t NullIndex
A null index in a block allocator.
Definition: BlockAllocator.h:38
@ Block
The socket would have blocked.
The namespace for gf classes.