Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/fceux.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/memory.cpp')
-rw-r--r--src/utils/memory.cpp62
1 files changed, 38 insertions, 24 deletions
diff --git a/src/utils/memory.cpp b/src/utils/memory.cpp
index 93bc3af9..fa5d65b4 100644
--- a/src/utils/memory.cpp
+++ b/src/utils/memory.cpp
@@ -28,18 +28,34 @@
#include "../fceu.h"
#include "memory.h"
+void *FCEU_amalloc(size_t size, size_t alignment)
+{
+ size = (size + alignment - 1) & ~(alignment-1);
+
+ #ifdef _MSC_VER
+ void *ret = _aligned_malloc(size,alignment);
+ #else
+ void *ret = aligned_alloc(alignment,size);
+ #endif
+
+ if(!ret)
+ FCEU_abort("Error allocating memory!");
+
+ return ret;
+}
+
+void FCEU_afree(void* ptr)
+{
+ #ifdef _MSC_VER
+ _aligned_free(ptr);
+ #else
+ free(ptr);
+ #endif
+}
+
static void *_FCEU_malloc(uint32 size)
{
- //do not add an aligned allocation function. if a larger alignment is needed, change this constant to use it for all allocations.
- static const int alignment = 32;
-
- size = (size + alignment - 1) & ~(alignment-1);
-
- #ifdef _MSC_VER
- void *ret = _aligned_malloc(size,alignment);
- #else
- void *ret = aligned_alloc(alignment,size);
- #endif
+ void* ret = malloc(size);
if(!ret)
FCEU_abort("Error allocating memory!");
@@ -49,22 +65,17 @@ static void *_FCEU_malloc(uint32 size)
static void _FCEU_free(void* ptr)
{
- #ifdef _MSC_VER
- _aligned_free(ptr);
- #else
free(ptr);
- #endif
}
-///allocates the specified number of bytes. exits process if this fails
void *FCEU_gmalloc(uint32 size)
{
- void *ret = _FCEU_malloc(size);
+ void *ret = _FCEU_malloc(size);
- // initialize according to RAMInitOption, default zero
- FCEU_MemoryRand((uint8*)ret,size,true);
+ // initialize according to RAMInitOption, default zero
+ FCEU_MemoryRand((uint8*)ret,size,true);
- return ret;
+ return ret;
}
void *FCEU_malloc(uint32 size)
@@ -74,13 +85,11 @@ void *FCEU_malloc(uint32 size)
return ret;
}
-//frees memory allocated with FCEU_gmalloc
void FCEU_gfree(void *ptr)
{
_FCEU_free(ptr);
}
-//frees memory allocated with FCEU_malloc
void FCEU_free(void *ptr)
{
_FCEU_free(ptr);
@@ -96,8 +105,13 @@ void FCEU_dfree(void *ptr)
return FCEU_free(ptr);
}
-void FCEU_abort(const char* message)
-{
+void* FCEU_realloc(void* ptr, size_t size)
+{
+ return realloc(ptr,size);
+}
+
+void FCEU_abort(const char* message)
+{
if(message) FCEU_PrintError(message);
abort();
-}
+}