Просмотр исходного кода

Replaced use of __STDCPP_DEFAULT_NEW_ALIGNMENT__ with JPH_DEFAULT_ALLOCATE_ALIGNMENT so that it can be overridden in case a custom allocator has different alignment rules

Jorrit Rouwe 5 дней назад
Родитель
Сommit
d3356e2b3a
4 измененных файлов с 9 добавлено и 3 удалено
  1. 6 0
      Jolt/Core/Core.h
  2. 1 1
      Jolt/Core/HashTable.h
  3. 1 1
      Jolt/Core/STLAllocator.h
  4. 1 1
      Jolt/Core/TempAllocator.h

+ 6 - 0
Jolt/Core/Core.h

@@ -534,6 +534,12 @@ static_assert(sizeof(uint64) == 8, "Invalid size of uint64");
 	#error Undefined
 #endif
 
+// Default memory allocation alignment.
+// This define can be overridden in case the user provides an Allocate function that has a different alignment than the platform default.
+#ifndef JPH_DEFAULT_ALLOCATE_ALIGNMENT
+	#define JPH_DEFAULT_ALLOCATE_ALIGNMENT __STDCPP_DEFAULT_NEW_ALIGNMENT__
+#endif
+
 // Cache line size (used for aligning to cache line)
 #ifndef JPH_CACHE_LINE_SIZE
 	#define JPH_CACHE_LINE_SIZE 64

+ 1 - 1
Jolt/Core/HashTable.h

@@ -842,7 +842,7 @@ public:
 
 private:
 	/// If this allocator needs to fall back to aligned allocations because the type requires it
-	static constexpr bool	cNeedsAlignedAllocate = alignof(KeyValue) > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
+	static constexpr bool	cNeedsAlignedAllocate = alignof(KeyValue) > JPH_DEFAULT_ALLOCATE_ALIGNMENT;
 
 	/// Max load factor is cMaxLoadFactorNumerator / cMaxLoadFactorDenominator
 	static constexpr uint64	cMaxLoadFactorNumerator = 7;

+ 1 - 1
Jolt/Core/STLAllocator.h

@@ -44,7 +44,7 @@ public:
 	inline					STLAllocator(const STLAllocator<T2> &) { }
 
 	/// If this allocator needs to fall back to aligned allocations because the type requires it
-	static constexpr bool	needs_aligned_allocate = alignof(T) > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
+	static constexpr bool	needs_aligned_allocate = alignof(T) > JPH_DEFAULT_ALLOCATE_ALIGNMENT;
 
 	/// Allocate memory
 	inline pointer			allocate(size_type inN)

+ 1 - 1
Jolt/Core/TempAllocator.h

@@ -18,7 +18,7 @@ public:
 	JPH_OVERRIDE_NEW_DELETE
 
 	/// If this allocator needs to fall back to aligned allocations because JPH_RVECTOR_ALIGNMENT is bigger than the platform default
-	static constexpr bool			needs_aligned_allocate = JPH_RVECTOR_ALIGNMENT > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
+	static constexpr bool			needs_aligned_allocate = JPH_RVECTOR_ALIGNMENT > JPH_DEFAULT_ALLOCATE_ALIGNMENT;
 
 	/// Destructor
 	virtual							~TempAllocator() = default;