Derive-C
Loading...
Searching...
No Matches
staticbump.c File Reference
#include <assert.h>
#include <stdio.h>
#include <derive-c/allocs/staticbump/template.h>
Include dependency graph for staticbump.c:

Go to the source code of this file.

Macros

#define CAPACITY   1024
#define SELF   foopool

Functions

void foopool_raw_example ()
int main ()

Macro Definition Documentation

◆ CAPACITY

#define CAPACITY   1024

Definition at line 5 of file staticbump.c.

◆ SELF

#define SELF   foopool

Definition at line 6 of file staticbump.c.

Function Documentation

◆ foopool_raw_example()

void foopool_raw_example ( )

Definition at line 9 of file staticbump.c.

9 {
10 foopool pool = foopool_new();
11
12 void* ptr1 = foopool_malloc(&pool, 100);
13 assert(ptr1 != NULL);
14
15 void* ptr2 = foopool_malloc(&pool, 200);
16 assert(ptr2 != NULL);
17
18 // Check the used size
19 size_t used = foopool_get_used(&pool);
20 assert(used == 100 + 200 + foopool_metadata_size * 2);
21
22 foopool_free(&pool, ptr1);
23
24 // reallocated in place
25 void* ptr2_realloc = foopool_realloc(&pool, ptr2, 300);
26 assert(ptr2_realloc == ptr2);
27
28 foopool_free(&pool, ptr2_realloc);
29
30 foopool_clear(&pool);
31
32 // we can allocate at capacity:
33 void* ptr3 = foopool_malloc(&pool, 1024 - foopool_metadata_size);
34 assert(ptr3 != NULL);
35 foopool_free(&pool, ptr3);
36 foopool_clear(&pool);
37
38 // But we cannot allocate more than capacity
39 void* ptr4 = foopool_malloc(&pool, 1024 - foopool_metadata_size + 1);
40 assert(ptr4 == NULL);
41 assert(foopool_get_used(&pool) == 0);
42}
Here is the caller graph for this function:

◆ main()

int main ( )
Examples
complex/employees.c, complex/prime_sieve.c, structures/arena.c, structures/hashmap.c, structures/option.c, structures/staticvec.c, and structures/vector.c.

Definition at line 44 of file staticbump.c.

void foopool_raw_example()
Definition staticbump.c:9
Here is the call graph for this function:
Here is the caller graph for this function: