#pragma once #include "core.h" typedef union APoolElement APoolElement; union APoolElement { APoolElement *next; // offset from start to next free block (when not allocated) }; typedef struct APool APool; struct APool { APoolElement *free_list; // free list U8 *start; // start of user buffer Allocator *allocator; U32 element_size; // aligned size of each block U32 n_elements; // total number of blocks U32 align; // alignment }; enum { APOOL_AUTOGROW = 0 }; #define apool_create(arena, n_elements, type) \ apool_create_ex(arena, n_elements, sizeof(type), alignof(type)); APool *apool_create_ex(Allocator *allocator, U32 n_elements, U32 element_size, uint32_t element_align); void *apool_alloc(APool *pool); void apool_free(APool *pool, void *element);