Nugget
Loading...
Searching...
No Matches
Functions
alloc.h File Reference
#include <stddef.h>
#include <stdint.h>
Include dependency graph for alloc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

voidpsyqo_malloc (size_t size)
 Allocates memory from the heap.
 
voidpsyqo_realloc (void *ptr, size_t size)
 Re-allocates memory from the heap.
 
void psyqo_free (void *ptr)
 Frees memory from the heap.
 
voidpsyqo_heap_start ()
 Returns the pointer to the beginning of the heap.
 
voidpsyqo_heap_end ()
 Returns the pointer to the end of the heap.
 

Function Documentation

◆ psyqo_free()

void psyqo_free ( void ptr)

Frees memory from the heap.

This function behaves as you'd expect from typical free. Calling this function with a NULL pointer is a no-op.

Parameters
ptrThe pointer to the memory to free.

◆ psyqo_heap_end()

void * psyqo_heap_end ( )

Returns the pointer to the end of the heap.

This function will return the pointer to the end of the heap. The heap works lazily, and this function may return a NULL pointer. Once it returns a non-NULL pointer, it will approximately correspond to the current end of the heap. The heap may actually be larger than this pointer on occasion. The heap will always grow, and never shrink.

Returns
void* The end of the heap.

◆ psyqo_heap_start()

void * psyqo_heap_start ( )

Returns the pointer to the beginning of the heap.

This function will return the pointer to the beginning of the heap. The heap works lazily, and this function may return a NULL pointer, but once it returns a non-NULL pointer, it will always return the same pointer.

Returns
void* The beginning of the heap.

◆ psyqo_malloc()

void * psyqo_malloc ( size_t  size)

Allocates memory from the heap.

This function behaves as you'd expect from typical malloc. Allocating 0 bytes will return a valid pointer, which can be freed. Guarantees to align the memory to 8 bytes.

Parameters
sizeThe amount of bytes to allocate.
Returns
void* The memory allocated.

◆ psyqo_realloc()

void * psyqo_realloc ( void ptr,
size_t  size 
)

Re-allocates memory from the heap.

This function behaves as you'd expect from typical realloc. Allocating 0 bytes with a NULL pointer will return a valid pointer, which can be freed. Allocating 0 bytes with a valid pointer will behave as if free was called. Re-allocating a pointer to a smaller size is always guaranteed to succeed and to return the same pointer. Re-allocating a pointer to a larger size may fail, in which case, it will return NULL. Passing a NULL pointer will behave like a call to malloc.

Parameters
ptrThe pointer to the memory to re-allocate.
sizeThe amount of bytes to allocate.
Returns
void* The memory allocated.