mm (Memory Management)

Header: udo/mm.h

Table of contents (click to go)

Macros

Enums

Unions

Structs

  1. udo_mm

Functions

  1. udo_mm_alloc()

  2. udo_mm_sub_alloc()

  3. udo_mm_sub_alloc_get_size()

  4. udo_mm_free()

  5. udo_mm_destroy()

API Documentation

This interface was built to force caller
to be more consciously concern about heap
based virtual memory management.

udo_mm (private)

struct udo_mm
struct udo_log_error_struct err;
size_t buff_sz;
size_t data_sz;
size_t ab_sz;
size_t offset;
err
Stores information about the error that occured
for the given context and may later be retrieved.
by caller.
buff_sz
Full size of the struct udo_mm context.
Not all bytes in the buffer are writable.
data_sz
Full size of the caller writable data.
ab_sz
The amount of available bytes the caller
can still write to.
offset
Buffer offset used when allocating new blocks
in constant time. Caller may not of used the
entire buffer before re-allocation. Member is
used to keep track of end of buffer where data
exist.

udo_mm_alloc

struct udo_mm *udo_mm_alloc(struct udo_mm *mm, const size_t size);
Returns pointer to an allocated block of heap
memory. The goal of this is to allocate a large
block of memory once. If re-allocation required
pass the previous large block to clone all data.

Addresses returned from function should not
be used to write to. Writable addresses
are return from a call to udo_mm_sub_alloc().

Param

Decription

mm

If NULL the inital allocation will be performed.
If not NULL must pass a pointer to a struct udo_mm.

size

Size of data caller may allocate. If the
size is greater than the larger block
remapping of memory will occur.
Returns:
on success: Pointer to a struct udo_mm
on failure: NULL

udo_mm_sub_alloc

void *udo_mm_sub_alloc(struct udo_mm *mm, size_t size);
Returns pointer to an allocated block of heap
memory. From the allocated larger block of
memory sub-allocate from that larger block.

Addresses returned from function can be
used for writing.

Param

Decription

mm

Must pass a pointer to a struct udo_mm.

size

Size of buffer to sub-allocate.
Returns:
on success: Pointer to writable memory
on failure: NULL

udo_mm_sub_alloc_get_size

void *udo_mm_sub_alloc_get_size(const void *data);
Returns size of an allocated heap
memory sub block.

Param

Decription

data

Must pass address returned after
Returns:
on success: Size of allocated sub block
on failure: (size_t)-1

udo_mm_free

void udo_mm_free(struct udo_mm *mm, const void *data);
Wipes the bytes at a given subregion of memory.
Shifts the memory after the subregion over to
the start of the wiped subregion.

NOTE: This function should be used sparingly
as the caller would have to keep track of the
new pointer address for every object allocated.
It’s better to only allocate memory if you know
the address it resides in won’t change. Usages
of bounded buffer for strings is encouraged.

Param

Decription

mm

Must pass a pointer to a struct udo_mm.

data

Address to the data caller wants to zero out.

udo_mm_destroy

void udo_mm_destroy(struct udo_mm *mm);
Free’s the large block of allocated memory created after

Param

Decription

flops

Must pass a pointer to a struct udo_mm.