blob: ed2935e05a99cf285245aa9c7fd441b615da321a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# Mempool
A memory pool implementation.
Each block in the pool is tagged with a boolean value that indicates whether the
block is free or in use. The allocator otherwise maintains little additional
information. Therefore, some operations have linear-time complexity.
Specifically:
- Allocating a block scans the pool for the next free block in linear time.
- Freeing a block runs in constant time.
- Iterating over the pool's used blocks is linear over the number of blocks in
the pool, as opposed to just the number of used blocks.
The allocator's internal data is also stored separately from the main array of
blocks so that the block data remains tightly packed.
For convenience of programming and debugging, free blocks in the mempool always
remain zeroed out. If your data structures are valid when zeroed out, then you
do not need to explicitly initialize them.
|