Standard library module
Butano standard library replacement.
Main differences against C++'s standard library is the usage of asserts instead of exceptions and that it avoids heap usage when possible.
Modules
- module Containers
- module Utilities
- module Functional
Files
- file bn_algorithm.h
- file bn_bit.h
- file bn_compare.h
- file bn_cstdlib.h
- file bn_cstring.h
- file bn_iterator.h
- file bn_limits.h
- file bn_type_traits.h
Functions
- auto malloc(int bytes) -> void*
- Allocates uninitialized storage in EWRAM.
- auto calloc(int num, int bytes) -> void*
- Allocates storage in EWRAM for an array of num objects of bytes size and initializes all bytes in it to zero.
- auto realloc(void* ptr, int new_bytes) -> void*
- Reallocates the given storage in the EWRAM.
- void free(void* ptr)
- Deallocates the storage previously allocated by bn::
malloc, bn:: calloc or bn:: realloc. - void memcpy(void* destination, const void* source, int bytes)
- Copies the given bytes from the object pointed to by source to the object pointed to by destination.
- void memset(void* destination, uint8_t value, int bytes)
- Copies the given value into each of the first given bytes of the object pointed to by destination.
- void memclear(void* destination, int bytes)
- Copies the value
0
into each of the first given bytes of the object pointed to by destination.
Function documentation
void* malloc(int bytes)
#include <bn_cstdlib.h>
Allocates uninitialized storage in EWRAM.
Parameters | |
---|---|
bytes | Bytes to allocate. |
Returns | On success, returns the pointer to the beginning of newly allocated memory. On failure, returns nullptr . |
To avoid a memory leak, the returned pointer must be deallocated with bn::
void* calloc(int num,
int bytes)
#include <bn_cstdlib.h>
Allocates storage in EWRAM for an array of num objects of bytes size and initializes all bytes in it to zero.
Parameters | |
---|---|
num | Number of objects. |
bytes | Size in bytes of each object. |
Returns | On success, returns the pointer to the beginning of newly allocated memory. On failure, returns nullptr . |
To avoid a memory leak, the returned pointer must be deallocated with bn::
void* realloc(void* ptr,
int new_bytes)
#include <bn_cstdlib.h>
Reallocates the given storage in the EWRAM.
Parameters | |
---|---|
ptr | Pointer to the storage to reallocate. |
new_bytes | New size in bytes of the reallocated storage. |
Returns | On success, returns the pointer to the beginning of newly allocated storage. On failure, returns nullptr . |
If ptr was not previously allocated by bn::
On success, the original pointer ptr is invalidated and any access to it is undefined behavior (even if reallocation was in-place).
To avoid a memory leak, the returned pointer must be deallocated with bn::
void free(void* ptr)
#include <bn_cstdlib.h>
Deallocates the storage previously allocated by bn::
Parameters | |
---|---|
ptr | Pointer to the storage to deallocate. It is invalidated and any access to it is undefined behavior. |
If ptr is nullptr
, the function does nothing.
If ptr was not previously allocated by bn::
void memcpy(void* destination,
const void* source,
int bytes)
#include <bn_cstring.h>
Copies the given bytes from the object pointed to by source to the object pointed to by destination.
Parameters | |
---|---|
destination | Pointer to the memory location to copy to. |
source | Pointer to the memory location to copy from. |
bytes | Number of bytes to copy. |
void memset(void* destination,
uint8_t value,
int bytes)
#include <bn_cstring.h>
Copies the given value into each of the first given bytes of the object pointed to by destination.
Parameters | |
---|---|
destination | Pointer to the object to fill. |
value | Fill byte. |
bytes | Number of bytes to fill. |
void memclear(void* destination,
int bytes)
#include <bn_cstring.h>
Copies the value 0
into each of the first given bytes of the object pointed to by destination.
Parameters | |
---|---|
destination | Pointer to the object to clear. |
bytes | Number of bytes to clear. |