C -> CPP
This commit is contained in:
107
src/util/memory.hpp
Normal file
107
src/util/memory.hpp
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* 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);
|
||||
Reference in New Issue
Block a user