bn::memory namespace
#include <bn_memory.h>

Memory related functions.

Contents

Functions

auto ewram_alloc(int bytes) -> void*
Allocates uninitialized storage in EWRAM.
void ewram_free(void* ptr)
Deallocates the space previously allocated by bn::ewram_alloc.
auto used_alloc_ewram() -> int
Returns the bytes of all allocated items in EWRAM with ewram_alloc.
auto available_alloc_ewram() -> int
Returns the bytes that still can be allocated in EWRAM with ewram_alloc.
auto used_items_ewram() -> int
Returns the items allocated in EWRAM with ewram_alloc.
auto available_items_ewram() -> int
Returns the items that still can be allocated in EWRAM with ewram_alloc.
auto used_stack_iwram() -> int
Returns the IWRAM used by the stack in bytes.
auto used_static_iwram() -> int
Returns the bytes of all static objects in IWRAM.
auto used_static_ewram() -> int
Returns the bytes of all static objects in EWRAM.
template<typename Type>
void copy(const Type& source_ref, int elements, Type& destination_ref)
Copies the given amount of elements from the object referenced by source_ref to the object referenced by destination_ref.
template<typename Type>
void clear(int elements, Type& destination_ref)
Clears (set to zero) the memory of the given amount of elements from the object referenced by destination_ref.
void set_bytes(uint8_t value, int bytes, void* destination_ptr)
Copies the given value into each of the first bytes of the object pointed to by destination_ptr.
void set_half_words(uint16_t value, int half_words, void* destination_ptr)
Copies the given value into each of the first half_words of the object pointed to by destination_ptr.
void set_words(unsigned value, int words, void* destination_ptr)
Copies the given value into each of the first words of the object pointed to by destination_ptr.
void decompress(compression_type compression, const void* source_ptr, int bytes, void* destination_ptr)
Decompresses the compressed data pointed to by source_ptr in the first bytes of the object pointed to by destination_ptr.

Function documentation

void* bn::memory::ewram_alloc(int bytes)

Allocates uninitialized storage in EWRAM.

Parameters
bytes Bytes to allocate.
Returns On success, returns the pointer to the beginning of newly allocated memory. To avoid a memory leak, the returned pointer must be deallocated with bn::ewram_free. On failure, returns a null pointer.

void bn::memory::ewram_free(void* ptr)

Deallocates the space previously allocated by bn::ewram_alloc.

Parameters
ptr Pointer to the memory to deallocate.

If ptr is a null pointer, the function does nothing.

If ptr was not previously allocated by bn::ewram_alloc, the behavior is undefined.

template<typename Type>
void bn::memory::copy(const Type& source_ref, int elements, Type& destination_ref)

Copies the given amount of elements from the object referenced by source_ref to the object referenced by destination_ref.

Parameters
source_ref Const reference to the memory location to copy from.
elements Number of elements to copy (not bytes).
destination_ref Reference to the memory location to copy to.

If the objects overlap, the behavior is undefined.

template<typename Type>
void bn::memory::clear(int elements, Type& destination_ref)

Clears (set to zero) the memory of the given amount of elements from the object referenced by destination_ref.

Parameters
elements Number of elements to clear (not bytes).
destination_ref Reference to the memory location to clear.

void bn::memory::set_bytes(uint8_t value, int bytes, void* destination_ptr)

Copies the given value into each of the first bytes of the object pointed to by destination_ptr.

Parameters
value Value to copy.
bytes Number of bytes to fill.
destination_ptr Pointer to the object to fill.

If the given size is greater than the size of the object pointed to by destination_ptr or it is not trivial, the behavior is undefined.

void bn::memory::set_half_words(uint16_t value, int half_words, void* destination_ptr)

Copies the given value into each of the first half_words of the object pointed to by destination_ptr.

Parameters
value Value to copy.
half_words Number of half words to fill.
destination_ptr Pointer to the object to fill.

If the given size is greater than the size of the object pointed to by destination_ptr or it is not trivial, the behavior is undefined.

void bn::memory::set_words(unsigned value, int words, void* destination_ptr)

Copies the given value into each of the first words of the object pointed to by destination_ptr.

Parameters
value Value to copy.
words Number of words to fill.
destination_ptr Pointer to the object to fill.

If the given size is greater than the size of the object pointed to by destination_ptr or it is not trivial, the behavior is undefined.

void bn::memory::decompress(compression_type compression, const void* source_ptr, int bytes, void* destination_ptr)

Decompresses the compressed data pointed to by source_ptr in the first bytes of the object pointed to by destination_ptr.

Parameters
compression Compression type.
source_ptr Compressed data to decompress.
bytes Number of decompressed bytes.
destination_ptr Destination of the decompressed data.

If the source and destination data overlap, the behavior is undefined.