This commit is contained in:
Nils O. Selåsdal
2026-06-15 10:50:54 +02:00
parent cec0cd966b
commit 2fed5cbe1b
4 changed files with 17 additions and 6 deletions
+2 -1
View File
@@ -168,12 +168,13 @@ APool *apool_create_ex(Arena *arena, U32 n_elements, U32 element_size, U32 eleme
U32 size = AlignUp(element_size, element_align);
APool *pool = arena_push_type(arena, APool);
Assert(pool != NULL);
pool->align = align;
pool->element_size = size;
pool->arena = arena;
pool->n_elements = n_elements;
pool->free_list = NULL;
pool->start == NULL;
pool->start = NULL;
if (size != APOOL_AUTOGROW) {
U32 total_size = n_elements * size; // Note(nos): guard against unreasonable sizes
+11 -2
View File
@@ -177,7 +177,8 @@ typedef unsigned __int128 U128;
#define CeilDiv(x, y) (((x) + ((y) - 1)) / (y))
/**
* Round x up to nearest multiple of y
* Round x up to nearest multiple of y:
* (((x) + (y) - 1) - (((x) + (y) - 1) % (y)))
* e.g. RoundUp(30,48) == 48
* e.g. RoundUp(49,48) == 96
*
@@ -185,7 +186,15 @@ typedef unsigned __int128 U128;
* @param y denominator
* @return x rounded up to nearest multiple of y
*/
#define RoundUpToMultiple(x, y) (CeilDiv((x), (y)) * (y))
#define RoundUpToMultiple(x, y) \
({ \
__typeof__(x) _x = (x); \
__typeof__(y) _y = (y); \
Assert(_y ! = 0); \
__typeof__(x) _tmp = _x + _y - 1; \
_tmp - _tmp % _y; \
})
/**
* Round x down to nearest multiple of y
+3 -2
View File
@@ -194,8 +194,8 @@ void miniarena_test1(void)
typedef struct PoolTest PoolTest;
struct PoolTest{
U32 n;
char name[32];
PoolTest *next;
char name[12];
};
void apool_test(void)
@@ -238,7 +238,7 @@ void apool_test(void)
for (PoolTest *p = list; p; p = p->next){
printf("Pooltest %u\n",p->n);
}
arena_free(&arena);
}
void apool_test_autogrow(void)
@@ -291,6 +291,7 @@ int main(int argc, char *argv[])
// arena_test_3();
// arena_test_4();
// miniarena_test1();
apool_test();
apool_test_autogrow();
}
+1 -1
View File
@@ -4,9 +4,9 @@
void *platform_malloc(size_t size);
U32 platform_page_size(void);
// Memory functions expect mem and size to be page aligned
void *memory_allocate_and_commit(size_t size);
void *memory_reserve(size_t size);
void memory_commit(void *mem, size_t size);
void memory_decommit(void *mem, size_t size);
void memory_free(void *mem, size_t size);