Let mem_rmalloc call mem_malloc instead of std::malloc

`mem_rmalloc` should use `mem_malloc` instead of `std::malloc`
to match the `mem_free` deallocation call.
This commit is contained in:
Sebastian Holtermann 2024-10-07 19:09:58 +02:00
parent 48c87750f4
commit 15095f8763

View File

@ -76,17 +76,6 @@
#include <cstdlib> #include <cstdlib>
#include <type_traits> #include <type_traits>
template<typename T> static inline T *mem_rmalloc()
{
static_assert(std::is_trivially_constructible_v<T> && std::is_trivially_destructible_v<T>);
return static_cast<T *>(std::malloc(sizeof(T)));
}
template<typename T> static inline T *mem_rmalloc(std::size_t nelem)
{
static_assert(std::is_trivially_constructible_v<T> && std::is_trivially_destructible_v<T>);
return static_cast<T *>(std::malloc(nelem * sizeof(T)));
}
// Memory management debugging // Memory management debugging
#ifdef MEM_USE_RTL #ifdef MEM_USE_RTL
#define mem_malloc(d) malloc(d) // Use this if your going to run BoundsChecker #define mem_malloc(d) malloc(d) // Use this if your going to run BoundsChecker
@ -137,4 +126,16 @@ bool mem_dumpmallocstofile(char *filename);
void mem_heapcheck(); void mem_heapcheck();
// type aware memory allocation
template<typename T> static inline T *mem_rmalloc()
{
static_assert(std::is_trivially_constructible_v<T> && std::is_trivially_destructible_v<T>);
return static_cast<T *>(mem_malloc(sizeof(T)));
}
template<typename T> static inline T *mem_rmalloc(std::size_t nelem)
{
static_assert(std::is_trivially_constructible_v<T> && std::is_trivially_destructible_v<T>);
return static_cast<T *>(mem_malloc(nelem * sizeof(T)));
}
#endif #endif