Переглянути джерело

Changed AlignedAllocate to default to posix_memalign (#738)

I'm in the process of implementing iOS support for Godot Jolt, and it turns out that aligned_alloc is only available on iOS >=13, as seen here. According to that header it also appears that aligned_alloc is not available on macOS versions prior to 10.15 (Catalina). What is available however is posix_memalign.

I figured instead of adding even more platform ifdef's to AlignedAllocate I would just simplify things a bit and always default to posix_memalign on anything but Windows, as this seems to be available on Android as well. Although, I'm not sure how this change fares on that one blue platform.

Also note that posix_memalign technically returns an error code, but seeing as how none of the other allocation functions had any error-handling I opted to just ignore it.
Mikael Hermansson 1 рік тому
батько
коміт
a58e5485fa
1 змінених файлів з 7 додано та 7 видалено
  1. 7 7
      Jolt/Core/Memory.cpp

+ 7 - 7
Jolt/Core/Memory.cpp

@@ -32,13 +32,15 @@ JPH_ALLOC_SCOPE void JPH_ALLOC_FN(Free)(void *inBlock)
 JPH_ALLOC_SCOPE void *JPH_ALLOC_FN(AlignedAllocate)(size_t inSize, size_t inAlignment)
 {
 #if defined(JPH_PLATFORM_WINDOWS)
-	// Microsoft doesn't implement C++17 std::aligned_alloc
+	// Microsoft doesn't implement posix_memalign
 	return _aligned_malloc(inSize, inAlignment);
-#elif defined(JPH_PLATFORM_ANDROID)
-	return memalign(inAlignment, AlignUp(inSize, inAlignment));
 #else
-	// Using aligned_alloc instead of std::aligned_alloc because the latter is not available on some macOS versions
-	return aligned_alloc(inAlignment, AlignUp(inSize, inAlignment));
+	void *block = nullptr;
+	JPH_SUPPRESS_WARNING_PUSH
+	JPH_GCC_SUPPRESS_WARNING("-Wunused-result")
+	posix_memalign(&block, inAlignment, inSize);
+	JPH_SUPPRESS_WARNING_POP
+	return block;
 #endif
 }
 
@@ -46,8 +48,6 @@ JPH_ALLOC_SCOPE void JPH_ALLOC_FN(AlignedFree)(void *inBlock)
 {
 #if defined(JPH_PLATFORM_WINDOWS)
 	_aligned_free(inBlock);
-#elif defined(JPH_PLATFORM_ANDROID)
-	free(inBlock);
 #else
 	free(inBlock);
 #endif