lpool: use offset to next, avoids pointer alignment requirments

This commit is contained in:
Nils O. Selåsdal
2026-05-12 20:18:25 +02:00
parent 0180ce47e5
commit c89b4d1d3c
3 changed files with 37 additions and 20 deletions
+3 -3
View File
@@ -9,7 +9,7 @@ extern "C" {
typedef union LPoolBlock LPoolBlock;
union LPoolBlock {
LPoolBlock *next; // next free block (when not allocated)
uint32_t next; // offset from start to next free block (when not allocated)
unsigned char data[0]; // data when allocated
};
@@ -30,8 +30,8 @@ union LPoolBlock {
typedef struct LPool LPool;
struct LPool {
LPoolBlock *free_list; // free list
LPoolBlock *start; // start of user buffer
LPoolBlock *end; // one past end of user buffer
uint8_t *start; // start of user buffer
uint8_t *end; // one past end of user buffer
uint32_t block_size; // aligned size of each block
uint32_t capacity; // number of blocks
uint32_t align; // alignment