Skip to content

Commit

Permalink
Let mem_rmalloc call mem_malloc instead of std::malloc
Browse files Browse the repository at this point in the history
′mem_rmalloc′ should use ′mem_malloc′ instead of ′std::malloc′
to match the ′mem_free′ deallocation call.
  • Loading branch information
sebholt committed Oct 7, 2024
1 parent 48c8775 commit 83d07b8
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions mem/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,6 @@
#include <cstdlib>
#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
#ifdef MEM_USE_RTL
#define mem_malloc(d) malloc(d) // Use this if your going to run BoundsChecker
Expand All @@ -106,10 +95,10 @@ template<typename T> static inline T *mem_rmalloc(std::size_t nelem)
extern bool Mem_low_memory_mode;
extern bool Mem_superlow_memory_mode; // DAJ

// use if you want to manually print out a memory error
// use if you want to manually print out a memory error
#define mem_error() mem_error_msg(__FILE__, __LINE__)

// initializes memory library.
// initializes memory library.
void mem_Init();

// shutsdown memory
Expand All @@ -124,7 +113,7 @@ void *mem_malloc_sub(int size, const char *file, int line);
// Frees a previously allocated block of memory
void mem_free_sub(void *memblock);

// prints out a memory error message
// prints out a memory error message
void mem_error_msg(const char *file, int line, int size = -1);

char *mem_strdup_sub(const char *src, const char *file, int line);
Expand All @@ -137,4 +126,16 @@ bool mem_dumpmallocstofile(char *filename);

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

0 comments on commit 83d07b8

Please sign in to comment.