kiba-engine
Macros | Functions
memory.h File Reference

Lightweight layer between platform and other engine components to enable tracing/monitoring. More...

#include <kiba/defines.h>
Include dependency graph for memory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define KB_KILOBYTE(n)   (n * 1024)
 
#define KB_MEGABYTE(n)   KB_KILOBYTE(KB_KILOBYTE(n))
 
#define KB_GIGABYTE(n)   KB_KILOBYTE(KB_MEGABYTE(n))
 

Functions

KB_LOCAL b8 memory_initialize (void)
 
KB_LOCAL void * memory_page_allocate (usize target_num_bytes, usize *res_num_bytes)
 
KB_LOCAL void memory_page_free (void *page_data)
 
KB_LOCAL void memory_shutdown (void)
 
KB_API void * memory_allocate (usize size)
 Allocate memory. More...
 
KB_API void memory_free (void *mem, usize size)
 Free memory. More...
 
KB_API void * memory_zero (void *mem, usize size)
 Zero out memory. More...
 
KB_API void * memory_set (void *mem, u8 byte, usize size)
 Set content of memory block. More...
 
KB_API void * memory_copy (void *dst, const void *src, usize size)
 Copy memory. More...
 
KB_API void * memory_aligned_address (void *addr, usize alignment)
 Calculate properly aligned memory block address. More...
 

Detailed Description

Lightweight layer between platform and other engine components to enable tracing/monitoring.

Definition in file memory.h.

Function Documentation

◆ memory_aligned_address()

KB_API void* memory_aligned_address ( void *  addr,
usize  alignment 
)

Calculate properly aligned memory block address.

Calculate a new address which is a multiple of the alignment provided. At most alignment bytes above provided address.

Parameters
addroriginal memory block addr
alignmentnumber of bytes to be aligned by
Returns
aligned new address

Definition at line 85 of file memory.c.

◆ memory_allocate()

KB_API void* memory_allocate ( usize  size)

Allocate memory.

Parameters
sizenumber of bytes to be allocated
Returns
pointer to beginning of allocated block (zeroed out)

Definition at line 72 of file memory.c.

Here is the call graph for this function:

◆ memory_copy()

KB_API void* memory_copy ( void *  dst,
const void *  src,
usize  size 
)

Copy memory.

Parameters
dstpointer to beginning of the destination memory block
srcpointer to beginning of the source memory block
sizenumber of bytes to be copied
Returns
pointer to beginning of the destination block

Definition at line 83 of file memory.c.

Here is the call graph for this function:

◆ memory_free()

KB_API void memory_free ( void *  mem,
usize  size 
)

Free memory.

Parameters
mempointer to beginning of memory block
sizenumber of bytes to be freed

Definition at line 77 of file memory.c.

Here is the call graph for this function:

◆ memory_set()

KB_API void* memory_set ( void *  mem,
u8  byte,
usize  size 
)

Set content of memory block.

Parameters
mempointer to beginning of memory block
bytethe value to set every byte to
sizenumber of bytes to be set
Returns
pointer to beginning of the block

Definition at line 81 of file memory.c.

Here is the call graph for this function:

◆ memory_zero()

KB_API void* memory_zero ( void *  mem,
usize  size 
)

Zero out memory.

Parameters
mempointer to beginning of memory block
sizenumber of bytes to be zeroed out
Returns
pointer to beginning of zeroed block

Definition at line 79 of file memory.c.

Here is the call graph for this function: