diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2018-11-26 23:46:55 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2018-11-26 23:46:55 -0800 |
commit | 3abb513923adb1f5238a62dd7c64c433a08d9d62 (patch) | |
tree | 58ce04e6d82548ea8a93446bd64a06af01e0749a /src/example.c |
*: initial commit
This is a simple allocator derived from the chunker in the
sparkler rototiller particle system module.
It's useful for pooling allocations of varying size with a
lot of churn. It also gives a convenient way of discarding
all allocations through a reset mechanism obviating the need
for granular freeing, where applicable.
Diffstat (limited to 'src/example.c')
-rw-r--r-- | src/example.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/example.c b/src/example.c new file mode 100644 index 0000000..12383fa --- /dev/null +++ b/src/example.c @@ -0,0 +1,35 @@ +#include <assert.h> + +#include "pad.h" + +typedef struct foo_t { + int x, y, z; +} foo_t; + +#define CHUNK_CNT 256 + +int main(int argc, char *argv[]) +{ + foo_t *f[10 * CHUNK_CNT]; + pad_t *p; + + p = pad_new(sizeof(foo_t) * 256); + assert(p); + + for (int n = 0; n < 10; n++) { + for (int i = 0; i < 10 * CHUNK_CNT; i++) + assert(f[i] = pad_get(p, sizeof(foo_t))); + + for (int i = 0; i < 10 * CHUNK_CNT; i++) + pad_put(f[i]); + + for (int i = 0; i < 10 * CHUNK_CNT; i++) + assert(f[i] = pad_get(p, sizeof(foo_t))); + + pad_reset(p); + } + + pad_free(p); + + return 0; +} |