C Container Collection (CCC)
Loading...
Searching...
No Matches
CCC_Allocator Struct Reference

The type passed by reference to any container function that may need to allocate memory. The allocation function controls allocation, resizing, and freeing of memory. The context pointer references any auxiliary information needed to support the allocation function. The context pointer is passed as the context argument of the CCC_Allocator_arguments type, when provided. More...

#include <types.h>

Detailed Description

The type passed by reference to any container function that may need to allocate memory. The allocation function controls allocation, resizing, and freeing of memory. The context pointer references any auxiliary information needed to support the allocation function. The context pointer is passed as the context argument of the CCC_Allocator_arguments type, when provided.

There are a few ways to pass this type when a container function requests a reference to it. First initialize it statically in a module.

static CCC_Allocator const std_allocator = { .allocate = std_allocate };
int
main(void) {
container_insert(&container, &(int){1}, &std_allocator);
return 0;
}
The type passed by reference to any container function that may need to allocate memory....
Definition: types.h:376
CCC_Allocator_interface * allocate
Definition: types.h:378

Or, construct the context inline.

int
main(void) {
struct Arena_allocator arena = arena_initialize();
container_insert(&container, &(int){1},
&(CCC_Allocator){.allocate = std_allocate});
return 0;
}

Or, pass an empty context when allocation is prohibited.

int
main(void) {
struct Arena_allocator arena = arena_initialize();
container_insert(&container, &(int){1}, &(CCC_Allocator){});
}

The context provided with this allocator is separate from the context provided to containers that accept context for comparison or hashing functions.

Data Fields

CCC_Allocator_interfaceallocate
 
void * context
 

Field Documentation

◆ allocate

CCC_Allocator_interface* CCC_Allocator::allocate

The allocator function to be passed to an allocating operation.

◆ context

void* CCC_Allocator::context

Additional state to pass to the allocator to help manage memory.


The documentation for this struct was generated from the following file: