47 lines
1.2 KiB
C
47 lines
1.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "lpool.h"
|
|
|
|
struct TestData {
|
|
float x[3];
|
|
float y[3];
|
|
float z[3];
|
|
float w[3];
|
|
};
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
_Alignas(16) uint8_t store[2048];
|
|
// uint8_t *store = malloc(1024 * 1024 - 17);
|
|
|
|
LPool pool;
|
|
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;
|
|
for (;;) {
|
|
struct TestData *t = lpool_alloc(&pool);
|
|
if (t == NULL) {
|
|
break;
|
|
}
|
|
allocs++;
|
|
}
|
|
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);
|
|
|
|
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;
|
|
}
|