Understand the half-fit allocation strategy
masterThe library implements a modified half-fit algorithm. Memory is allocated in fragments whose size is rounded up to the next integer power of two.
Key Characteristics:
- Constant-time complexity: Both allocation and deallocation are $O(1)$.
- Predictable fragmentation: The worst-case memory consumption is well-characterized, making it suitable for hard real-time and high-integrity systems.
- Metadata Overhead: Each allocation incurs an overhead $a$, defined by
O1HEAP_ALIGNMENT. This value also dictates the pointer alignment. On 32-bit platforms, this overhead is typically 8 bytes (2 $\times$ pointer width). - Cache Optimization: The implementation uses the most recently used memory fragments to minimize cache misses.
Comparison of Strategies:
| Allocation strategy | WCMC |
|---|---|
| First-fit | $H = M \ (1 + \lceil{} \log_2 n \rceil{})$ |
| Half-fit | $H = 2 M \ (1 + \lceil{} \log_2 n \rceil{})$ |
| Best-fit | $H = M \ (n - 2)$ |
| TLSF | (see best-fit) |