GATE
|
Memory allocation and type construction/destruction functions. More...
Typedefs | |
typedef gate_result_t(* | gate_mem_ctor_t) (void *dest) |
typedef gate_result_t(* | gate_mem_copyctor_t) (void *dest, void const *src) |
typedef void(* | gate_mem_dtor_t) (void *dest) |
Functions | |
GATE_CORE_API void * | gate_mem_alloc (gate_size_t sz) |
Allocates a block of memory on the process heap. | |
GATE_CORE_API void * | gate_mem_realloc (void *ptr, gate_size_t newsize) |
Re-allocates a block of memory. | |
GATE_CORE_API void | gate_mem_dealloc (void *ptr) |
Deallocates a block of memory. | |
GATE_CORE_API void * | gate_mem_copy (void *dst, void const *src, gate_size_t sz) |
Copies the requested amount of bytes from a source buffer to a destination buffer. | |
GATE_CORE_API void * | gate_mem_move (void *dst, void const *src, gate_size_t sz) |
Like gate_mem_copy() but handles overlapping areas of source and destination buffer. | |
GATE_CORE_API void | gate_mem_clear (void *dst, gate_size_t sz) |
Clears all bits in a given buffer (fills with zero) | |
GATE_CORE_API void | gate_mem_fill (void *dst, char chr, gate_size_t sz) |
Fills all bytes in a buffer with a given character. | |
GATE_CORE_API int | gate_mem_compare (void const *ptr1, void const *ptr2, gate_size_t sz) |
Compares two memory blocks byte by byte. | |
GATE_CORE_API void | gate_mem_reversebyteorder (void *ptr, gate_size_t sz) |
Reverts the byte order in a given buffer. | |
GATE_CORE_API void * | gate_mem_copy_reverse (void *dst, void const *src, gate_size_t sz) |
Copies bytes from a source to a destination buffer in reverse order. | |
GATE_CORE_API gate_size_t | gate_mem_align_size (gate_size_t sz) |
Returns a memory size that fits exactly in a aligned memory block. | |
GATE_CORE_API gate_result_t | gate_mem_copy_construct (void *dest_item, void const *src_item, gate_size_t item_size, gate_mem_copyctor_t ctor) |
Copy constructs a data type using memcpy or a given constructor function. | |
GATE_CORE_API void | gate_mem_destruct (void *dest_item, gate_mem_dtor_t dtor) |
Destructs a data type. | |
GATE_CORE_API gate_result_t | gate_mem_move_construct (void *dest_item, void *src_item, gate_size_t item_size, gate_mem_copyctor_t ctor, gate_mem_dtor_t dtor) |
Move-constructs a data type, copies the data from source to destination and destroys source afterwards. | |
GATE_CORE_API gate_bool_t | gate_mem_swap (void *item1, void *item2, gate_size_t item_size, gate_mem_copyctor_t ctor, gate_mem_dtor_t dtor) |
Swaps the contents of 2 type instances. | |
Memory allocation and type construction/destruction functions.
typedef gate_result_t(* gate_mem_ctor_t) (void *dest) |
object constructor function, initializes a type on a preallocated memory block
typedef gate_result_t(* gate_mem_copyctor_t) (void *dest, void const *src) |
object copy constructor function, initializes a type on a preallocated memory block
typedef void(* gate_mem_dtor_t) (void *dest) |
object destructor function, releases object resources, no deallocation of the pointer itself
GATE_CORE_API void * gate_mem_alloc | ( | gate_size_t | sz | ) |
Allocates a block of memory on the process heap.
[in] | sz | Amount of bytes to allocate (must be greater than zero) |
GATE_CORE_API void * gate_mem_realloc | ( | void * | ptr, |
gate_size_t | newsize ) |
Re-allocates a block of memory.
[in] | ptr | Pointer to already allocated block |
[in] | newsize | New requested size (must be greater than zero) |
GATE_CORE_API void gate_mem_dealloc | ( | void * | ptr | ) |
Deallocates a block of memory.
[in] | ptr | Pointer to allocated memory block |
GATE_CORE_API void * gate_mem_copy | ( | void * | dst, |
void const * | src, | ||
gate_size_t | sz ) |
Copies the requested amount of bytes from a source buffer to a destination buffer.
[in] | dst | Pointer to copy destination buffer |
[in] | src | Pointer to copy source buffer |
[in] | sz | Amount of bytes to copy |
dst
on success, or NULL in case of an error GATE_CORE_API void * gate_mem_move | ( | void * | dst, |
void const * | src, | ||
gate_size_t | sz ) |
Like gate_mem_copy() but handles overlapping areas of source and destination buffer.
[in] | dst | Pointer to copy destination buffer |
[in] | src | Pointer to copy source buffer |
[in] | sz | Amount of bytes to copy |
dst
on success, or NULL in case of an error GATE_CORE_API void gate_mem_clear | ( | void * | dst, |
gate_size_t | sz ) |
Clears all bits in a given buffer (fills with zero)
[in] | dst | Pointer to buffer to be cleared |
[in] | sz | Amount of bytes in buffer to be cleared |
GATE_CORE_API void gate_mem_fill | ( | void * | dst, |
char | chr, | ||
gate_size_t | sz ) |
Fills all bytes in a buffer with a given character.
[in] | dst | Pointer to buffer to be filled |
[in] | chr | character value used to fill the buffer |
[in] | sz | Amount of bytes in buffer to be filled |
GATE_CORE_API int gate_mem_compare | ( | void const * | ptr1, |
void const * | ptr2, | ||
gate_size_t | sz ) |
Compares two memory blocks byte by byte.
[in] | ptr1 | Pointer to first memory block |
[in] | ptr2 | Pointer to second memory block |
[in] | sz | Amount of bytes to compare |
GATE_CORE_API void gate_mem_reversebyteorder | ( | void * | ptr, |
gate_size_t | sz ) |
Reverts the byte order in a given buffer.
e.g. [1, 2, 3, 4, 5] will become [5, 4, 3, 2, 1]
[in] | ptr | Pointer to memory buffer |
[in] | sz | Amount of bytes in buffer |
GATE_CORE_API void * gate_mem_copy_reverse | ( | void * | dst, |
void const * | src, | ||
gate_size_t | sz ) |
Copies bytes from a source to a destination buffer in reverse order.
[in] | dst | Pointer to destination buffer |
[in] | src | Pointer to source buffer |
[in] | sz | Amount of bytes to copy in reverse order |
dst
or NULL in case of an error GATE_CORE_API gate_size_t gate_mem_align_size | ( | gate_size_t | sz | ) |
Returns a memory size that fits exactly in a aligned memory block.
[in] | sz | Memory size to be aligned |
sz
GATE_CORE_API gate_result_t gate_mem_copy_construct | ( | void * | dest_item, |
void const * | src_item, | ||
gate_size_t | item_size, | ||
gate_mem_copyctor_t | ctor ) |
Copy constructs a data type using memcpy or a given constructor function.
[out] | dest_item | Pointer to destination were type is constructed |
[in] | src_item | Pointer to source used to copy data from |
[in] | item_size | Size of data type (used for memcpy when ctor is NULL) |
[in] | ctor | Optional constructor function |
GATE_CORE_API void gate_mem_destruct | ( | void * | dest_item, |
gate_mem_dtor_t | dtor ) |
Destructs a data type.
[in] | dest_item | Pointer to type instance to be destroyed |
[in] | dtor | Optional destructor function used to release internals of dest_item |
GATE_CORE_API gate_result_t gate_mem_move_construct | ( | void * | dest_item, |
void * | src_item, | ||
gate_size_t | item_size, | ||
gate_mem_copyctor_t | ctor, | ||
gate_mem_dtor_t | dtor ) |
Move-constructs a data type, copies the data from source to destination and destroys source afterwards.
[out] | dest_item | Pointer to destination were type is constructed |
[in] | src_item | Pointer to source used to copy data from, will be destroyed if copying succeeds |
[in] | item_size | Size of data type (used for memcpy when ctor is NULL) |
[in] | ctor | Optional constructor function |
[in] | dtor | Optional destructor function |
GATE_CORE_API gate_bool_t gate_mem_swap | ( | void * | item1, |
void * | item2, | ||
gate_size_t | item_size, | ||
gate_mem_copyctor_t | ctor, | ||
gate_mem_dtor_t | dtor ) |
Swaps the contents of 2 type instances.
[out] | item1 | Pointer to type that shall hold the content of item2 |
[in] | item2 | Pointer to type that shall hold the content of item1 |
[in] | item_size | Size of data type (used for memcpy when ctor is NULL) |
[in] | ctor | Optional constructor function |
[in] | dtor | Optional destructor function |