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);
51 : m_firstFreeBlock(NullIndex)
64 if (m_firstFreeBlock != NullIndex) {
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 151 #endif // GF_SPATIAL_BLOCK_ALLOCATOR_H const T & operator[](std::size_t index) const
Access the object at a given index.
Definition: BlockAllocator.h:110
void dispose(std::size_t index)
Deallocate the object at the given index.
Definition: BlockAllocator.h:87
T & operator[](std::size_t index)
Access the object at a given index.
Definition: BlockAllocator.h:99
std::size_t getAllocated() const
Get the number of allocated objects.
Definition: BlockAllocator.h:129
The namespace for gf classes.
Definition: Action.h:35
An allocator of objects referenced by an index.
Definition: BlockAllocator.h:45
constexpr std::size_t NullIndex
A null index in a block allocator.
Definition: BlockAllocator.h:38
std::size_t allocate()
Allocate an object.
Definition: BlockAllocator.h:61
The socket would have blocked.
BlockAllocator()
Default constructor.
Definition: BlockAllocator.h:50
void clear()
Remove all objects at once.
Definition: BlockAllocator.h:119