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.
This commit is contained in:
18
pool_test.c
Normal file
18
pool_test.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user