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:
authorzeromus <zeromus@users.noreply.github.com>2022-08-24 04:28:07 +0300
committerzeromus <zeromus@users.noreply.github.com>2022-08-24 04:28:15 +0300
commit179a5f0ffa41a8b1d09c054ab4f1af10d794dff6 (patch)
tree571d55467011de216cf0b8d9957285be70e9aced
parentd0add7a609ec818b4bfb93ca586873b41847d3a9 (diff)
fix the size parameter of newly-introduced aligned_alloc call to be properly aligned (as the api requires)
-rw-r--r--src/utils/memory.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/utils/memory.cpp b/src/utils/memory.cpp
index 5ed626ea..066eb89c 100644
--- a/src/utils/memory.cpp
+++ b/src/utils/memory.cpp
@@ -30,10 +30,15 @@
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,32);
+ void *ret = _aligned_malloc(size,alignment);
#else
- void *ret = aligned_alloc(32,size);
+ void *ret = aligned_alloc(alignment,size);
#endif
if(!ret)
@@ -74,13 +79,13 @@ void *FCEU_malloc(uint32 size)
return ret;
}
-///frees memory allocated with FCEU_gmalloc
+//frees memory allocated with FCEU_gmalloc
void FCEU_gfree(void *ptr)
{
_FCEU_free(ptr);
}
-///frees memory allocated with FCEU_malloc
+//frees memory allocated with FCEU_malloc
void FCEU_free(void *ptr)
{
_FCEU_free(ptr);