/** * Copyright (c) 2022 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #pragma once #include "dawnsharedlibs.hpp" #define DAWN_MEMORY_TRACKING 1 static void * memoryCallMalloc(const size_t size) { return malloc(size); } static void * memoryCallCalloc(const size_t num, const size_t size) { return calloc(num, size); } static void memoryCallFree(void *p) { free(p); } static void * memoryCallRealloc(void *p, size_t newSize) { return realloc(p, newSize); } /** * Allocate some space in memory to use for your needs. Memory allocation may * change how it functions later on to keep things nice and efficient. For now * this is just an API forward for malloc. * * @param size Size of the array you wish to buffer. * @return Pointer to the space in memory to use. */ void * memoryAllocate(const size_t size); /** * Allocate space in memory, where all values are set to 0 (in binary space). * * @param count Count of elements to allocate. * @param size Size of each element to allocate. * @return Pointer to the space in memory to use. */ void * memoryAllocateEmpty(const size_t count, const size_t size); /** * Free some previously allocated memory space. * @param pointer Pointer in memory to free. */ void memoryFree(void *pointer); /** * Reallocate a part of memory. Reallocation simply creates a new buffer that * will take all of the existing contents and then free's the original buffer. * * @param pointer Pointer to pointer in memory that you wish to re-allocate. * @param newSize The new size of the buffer. * @return Pointer to the new buffer. */ void * memoryReallocate(void *pointer, size_t newSize); /** * Copies data from one buffer to another. Typically used for array operations. * * @param source Source pointer. * @param destination Destination buffer. * @param size Size in bytes of data to copy. */ void memoryCopy(void *source, void *destination, size_t size); /** * Compares the data within two memory banks. Shorthand for memcpy. * * @param left Left item to compare. * @param right Right item to compare. * @param size Count of bytes to compare. * @return 0 for equal, <0 for left being greater, >0 for right being greater. */ int32_t memoryCompare(const void *left, const void *right, const size_t size); /** * Fill destination with a repeating set of bytes. * * @param dest Destination pointer in memory. * @param data Data byte to write. * @param length How many times to write that byte. */ void memorySet(void *dest, uint8_t data, size_t length); /** * Initializes the memory management system. */ void memoryInit(); /** * Disposes of the memory management system. */ void memoryDispose();