Clean up lpool

This commit is contained in:
Nils O. Selåsdal
2026-05-13 00:11:49 +02:00
parent c89b4d1d3c
commit d04b151279
3 changed files with 46 additions and 28 deletions
+19 -5
View File
@@ -1,4 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "lpool.h"
struct TestData {
@@ -10,9 +12,11 @@ struct TestData {
int main(int argc, char *argv[])
{
_Alignas(16) uint8_t store[2048];
//_Alignas(16) uint8_t store[2048];
uint8_t *store = malloc(2048);
LPool pool;
lpool_init(&pool, store, sizeof store, sizeof(struct TestData), _Alignof(struct TestData));
lpool_init(&pool, store, 2048, sizeof(struct TestData), _Alignof(struct TestData));
printf("align=%u capacity=%u block_size=%u\n", pool.align, pool.capacity, pool.block_size);
struct TestData *data = lpool_alloc(&pool);
size_t allocs = 1;
@@ -23,11 +27,21 @@ int main(int argc, char *argv[])
}
allocs++;
}
printf("Total allocs = %zu\n", allocs);
printf("alloc succeded = %d\n", lpool_alloc(&pool) != NULL);
printf("Total allocs = %zu, used = %u\n", allocs, pool.used);
printf("alloc succeded = %d used = %u\n", lpool_alloc(&pool) != NULL, pool.used);
lpool_free(&pool, data);
printf("alloc succeded = %d used = %u\n", lpool_alloc(&pool) != NULL, pool.used);
printf("alloc succeded = %d\n", lpool_alloc(&pool) != NULL);
lpool_reset(&pool);
allocs = 0;
for (;;) {
struct TestData *t = lpool_alloc(&pool);
if (t == NULL) {
break;
}
allocs++;
}
printf("Total allocs = %zu, used = %u\n", allocs, pool.used);
return 0;
}