lang/pool_test.c
r4 63af3e907b add assignment operator and unify memory pools
The unification of memory pools also fixed some memory leaks and
hopefully reduced the mallocs of identifier strings significantly by
giving them the same pool as the token stream.
2021-12-21 11:40:49 +01:00

19 lines
461 B
C

#include "util.c"
typedef struct Test {
char a_string[64];
} Test;
int main(void) {
Pool *p = pool_new(1);
Test *t = pool_alloc(p, sizeof(Test));
strcpy(t->a_string, "a test string");
Test *tarr = pool_alloc(p, sizeof(Test) * 32);
strcpy(tarr[31].a_string, "another test string");
char *c = pool_alloc(p, 1);
*c = 'a';
Test *largearr = pool_alloc(p, sizeof(Test) * 1024);
strcpy(largearr[1023].a_string, "yet another test string");
pool_term(p);
}