Pyrogenesis trunk
Macros | Functions
dynarray.cpp File Reference
#include "precompiled.h"
#include "lib/allocators/dynarray.h"
#include "lib/alignment.h"
#include "lib/sysdep/vm.h"
#include <cstring>
#include <string>
Include dependency graph for dynarray.cpp:

Macros

#define CHECK_DA(da)   RETURN_STATUS_IF_ERR(validate_da(da))
 

Functions

static Status validate_da (DynArray *da)
 
Status da_alloc (DynArray *da, size_t max_size)
 ready the DynArray object for use. More...
 
Status da_free (DynArray *da)
 free all memory (address space + physical) that constitutes the given array. More...
 
Status da_set_size (DynArray *da, size_t new_size)
 expand or shrink the array: changes the amount of currently committed (i.e. More...
 
Status da_reserve (DynArray *da, size_t size)
 Make sure at least <size> bytes starting at da->pos are committed and ready for use. More...
 
Status da_append (DynArray *da, const void *data, size_t size)
 "write" to array, i.e. More...
 

Macro Definition Documentation

◆ CHECK_DA

#define CHECK_DA (   da)    RETURN_STATUS_IF_ERR(validate_da(da))

Function Documentation

◆ da_alloc()

Status da_alloc ( DynArray da,
size_t  max_size 
)

ready the DynArray object for use.

no virtual memory is actually committed until calls to da_set_size.

Parameters
daDynArray.
max_sizesize [bytes] of address space to reserve (*); the DynArray can never expand beyond this. (* rounded up to next page size multiple)
Returns
Status.

◆ da_append()

Status da_append ( DynArray da,
const void *  data_src,
size_t  size 
)

"write" to array, i.e.

copy from the given buffer.

starts at offset DynArray.pos and advances this.

Parameters
daDynArray.
data_srcsource memory
size[bytes] to copy
Returns
Status.

◆ da_free()

Status da_free ( DynArray da)

free all memory (address space + physical) that constitutes the given array.

use-after-free is impossible because the memory is unmapped.

Parameters
daDynArray* zeroed afterwards.
Returns
Status

◆ da_reserve()

Status da_reserve ( DynArray da,
size_t  size 
)

Make sure at least <size> bytes starting at da->pos are committed and ready for use.

Parameters
daDynArray*
sizeMinimum amount to guarantee [bytes]
Returns
Status

◆ da_set_size()

Status da_set_size ( DynArray da,
size_t  new_size 
)

expand or shrink the array: changes the amount of currently committed (i.e.

usable) memory pages.

Parameters
daDynArray.
new_sizetarget size (rounded up to next page multiple). pages are added/removed until this is met.
Returns
Status.

◆ validate_da()

static Status validate_da ( DynArray da)
static