diff --git a/Redcraft.Utility/Source/Public/Memory/Alignment.h b/Redcraft.Utility/Source/Public/Memory/Alignment.h index d7b4a9b..170058a 100644 --- a/Redcraft.Utility/Source/Public/Memory/Alignment.h +++ b/Redcraft.Utility/Source/Public/Memory/Alignment.h @@ -9,35 +9,27 @@ NAMESPACE_MODULE_BEGIN(Utility) NAMESPACE_BEGIN(Memory) -template +template requires TIsIntegral::Value || TIsPointer::Value FORCEINLINE constexpr T Align(T InValue, size_t Alignment) { - static_assert(TIsIntegral::Value || TIsPointer::Value, "Align expects an integer or pointer type"); - return (T)(((uintptr)(InValue) + static_cast(Alignment) - 1) & ~(static_cast(Alignment) - 1)); } -template +template requires TIsIntegral::Value || TIsPointer::Value FORCEINLINE constexpr T AlignDown(T InValue, size_t Alignment) { - static_assert(TIsIntegral::Value || TIsPointer::Value, "AlignDown expects an integer or pointer type"); - return (T)((uintptr)(InValue) & ~(static_cast(Alignment) - 1)); } -template +template requires TIsIntegral::Value || TIsPointer::Value FORCEINLINE constexpr T AlignArbitrary(T InValue, size_t Alignment) { - static_assert(TIsIntegral::Value || TIsPointer::Value, "AlignArbitrary expects an integer or pointer type"); - return (T)((((uintptr)(InValue) + static_cast(Alignment) - 1) / static_cast(Alignment)) * static_cast(Alignment)); } -template +template requires TIsIntegral::Value || TIsPointer::Value FORCEINLINE constexpr bool IsAligned(T InValue, size_t Alignment) { - static_assert(TIsIntegral::Value || TIsPointer::Value, "IsAligned expects an integer or pointer type"); - return !((uintptr)(InValue) & (static_cast(Alignment) - 1)); } diff --git a/Redcraft.Utility/Source/Public/Memory/Memory.h b/Redcraft.Utility/Source/Public/Memory/Memory.h index d1a3c38..cba328e 100644 --- a/Redcraft.Utility/Source/Public/Memory/Memory.h +++ b/Redcraft.Utility/Source/Public/Memory/Memory.h @@ -13,18 +13,18 @@ NAMESPACE_MODULE_BEGIN(Utility) NAMESPACE_BEGIN(Memory) -inline constexpr size_t DEFAULT_ALIGNMENT = 0; -inline constexpr size_t MINIMUM_ALIGNMENT = 8; +inline constexpr size_t DefaultAlignment = 0; +inline constexpr size_t MinimumAlignment = 8; #ifdef __cpp_lib_hardware_interference_size -inline constexpr size_t DESTRUCTIVE_INTERFERENCE = std::hardware_destructive_interference_size; -inline constexpr size_t CONSTRUCTIVE_INTERFERENCE = std::hardware_constructive_interference_size; +inline constexpr size_t DestructiveInterference = std::hardware_destructive_interference_size; +inline constexpr size_t ConstructiveInterference = std::hardware_constructive_interference_size; #else -inline constexpr size_t DESTRUCTIVE_INTERFERENCE = 64; -inline constexpr size_t CONSTRUCTIVE_INTERFERENCE = 64; +inline constexpr size_t DestructiveInterference = 64; +inline constexpr size_t ConstructiveInterference = 64; #endif @@ -89,10 +89,10 @@ FORCEINLINE void SystemFree(void* Ptr) std::free(Ptr); } -REDCRAFTUTILITY_API void* Malloc(size_t Count, size_t Alignment = DEFAULT_ALIGNMENT); -REDCRAFTUTILITY_API void* Realloc(void* Ptr, size_t Count, size_t Alignment = DEFAULT_ALIGNMENT); +REDCRAFTUTILITY_API void* Malloc(size_t Count, size_t Alignment = DefaultAlignment); +REDCRAFTUTILITY_API void* Realloc(void* Ptr, size_t Count, size_t Alignment = DefaultAlignment); REDCRAFTUTILITY_API void Free(void* Ptr); -REDCRAFTUTILITY_API size_t QuantizeSize(size_t Count, size_t Alignment = DEFAULT_ALIGNMENT); +REDCRAFTUTILITY_API size_t QuantizeSize(size_t Count, size_t Alignment = DefaultAlignment); NAMESPACE_END(Memory)