Files
dusk/src/util/memory.hpp
Dominic Masters bfdc0e8462
Some checks failed
Build Dusk / build-linux (push) Failing after 1m16s
Build Dusk / build-psp (push) Failing after 1m14s
Input (first pass)
2025-12-23 17:33:46 +10:00

107 lines
2.5 KiB
C++

/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "Dusk.hpp"
/**
* Allocates memory.
*
* @param size The size of the memory to allocate.
* @return The allocated memory.
*/
void * memoryAllocate(const size_t size);
/**
* Frees memory.
*
* @param ptr The memory to free.
*/
void memoryFree(void *ptr);
/**
* Copies memory.
*
* @param dest The destination to copy to.
* @param src The source to copy from.
* @param size The size of the memory to copy.
*/
void memoryCopy(void *dest, const void *src, const size_t size);
/**
* Sets memory.
*
* @param dest The destination to set.
* @param value The value to set.
* @param size The size of the memory to set.
*/
void memorySet(void *dest, const uint8_t value, const size_t size);
/**
* Zeroes memory.
*
* @param dest The destination to zero.
* @param size The size of the memory to zero.
*/
void memoryZero(void *dest, const size_t size);
/**
* Copies memory, ensuring that the memory range is as expected, typically this
* is done if you're trying to reshape data in a buffer. Extremely useful in
* copying data to a shader buffer.
*
* @param dest The destination to copy to.
* @param start The start of the source to copy from.
* @param end The end of the source to copy from.
* @param sizeMax The maximum size of the memory to copy.
*/
void memoryCopyRangeSafe(
void *dest,
const void *start,
const void *end,
const size_t sizeMax
);
/**
* Moves memory.
*
* @param dest The destination to move to.
* @param src The source to move from.
* @param size The size of the memory to move.
*/
void memoryMove(void *dest, const void *src, const size_t size);
/**
* Compares memory.
*
* @param a The first memory to compare.
* @param b The second memory to compare.
* @param size The size of the memory to compare.
* @return 0 if the memory is equal, < 0 if a < b, > 0 if a > b.
*/
int_t memoryCompare(
const void *a,
const void *b,
const size_t size
);
/**
* Reallocates memory.
*
* @param ptr The pointer to the memory to reallocate.
* @param size The new size of the memory.
*/
void memoryReallocate(void **ptr, const size_t size);
/**
* Reallocates memory, but copies existing data to the new memory.
*
* @param ptr The pointer to the memory to resize.
* @param oldSize The old size of the memory.
* @param newSize The new size of the memory.
*/
void memoryResize(void **ptr, const size_t oldSize, const size_t newSize);