Electroneum
regional.h File Reference

Go to the source code of this file.

Classes

struct  regional
 

Functions

struct regionalregional_create (void)
 
struct regionalregional_create_custom (size_t size)
 
void regional_free_all (struct regional *r)
 
void regional_destroy (struct regional *r)
 
void * regional_alloc (struct regional *r, size_t size)
 
void * regional_alloc_init (struct regional *r, const void *init, size_t size)
 
void * regional_alloc_zero (struct regional *r, size_t size)
 
char * regional_strdup (struct regional *r, const char *string)
 
void regional_log_stats (struct regional *r)
 
size_t regional_get_mem (struct regional *r)
 

Detailed Description

Regional allocator. Allocates small portions of of larger chunks. Based on region-allocator from NSD, but rewritten to be light.

Different from (nsd) region-allocator.h o does not have recycle bin o does not collect stats; just enough to answer get_mem() in use. o does not keep cleanup list o does not have function pointers to setup o allocs the regional struct inside the first block. o can take a block to create regional from. o blocks and large allocations are kept on singly linked lists.

Definition in file regional.h.

Function Documentation

◆ regional_alloc()

void* regional_alloc ( struct regional r,
size_t  size 
)

Allocate size bytes of memory inside regional. The memory is deallocated when region_free_all is called for this region.

Parameters
rthe region.
sizenumber of bytes.
Returns
: pointer to memory allocated.

◆ regional_alloc_init()

void* regional_alloc_init ( struct regional r,
const void *  init,
size_t  size 
)

Allocate size bytes of memory inside regional and copy INIT into it. The memory is deallocated when region_free_all is called for this region.

Parameters
rthe region.
initto copy.
sizenumber of bytes.
Returns
: pointer to memory allocated.

◆ regional_alloc_zero()

void* regional_alloc_zero ( struct regional r,
size_t  size 
)

Allocate size bytes of memory inside regional that are initialized to 0. The memory is deallocated when region_free_all is called for this region.

Parameters
rthe region.
sizenumber of bytes.
Returns
: pointer to memory allocated.

◆ regional_create()

struct regional* regional_create ( void  )

Create a new regional.

Returns
: newly allocated regional.

◆ regional_create_custom()

struct regional* regional_create_custom ( size_t  size)

Create a new region, with custom settings.

Parameters
sizelength of first block.
Returns
: newly allocated regional.

◆ regional_destroy()

void regional_destroy ( struct regional r)

Destroy regional. All memory associated with regional is freed as if regional_free_all was called, as well as destroying the regional struct.

Parameters
rto delete.

◆ regional_free_all()

void regional_free_all ( struct regional r)

Free all memory associated with regional. Only keeps the first block with the regional inside it.

Parameters
rthe region.

◆ regional_get_mem()

size_t regional_get_mem ( struct regional r)

get total memory size in use by region

◆ regional_log_stats()

void regional_log_stats ( struct regional r)

Debug print regional statistics to log

◆ regional_strdup()

char* regional_strdup ( struct regional r,
const char *  string 
)

Duplicate string and allocate the result in regional.

Parameters
rthe region.
stringnull terminated string.
Returns
: pointer to memory allocated.