Rename allocation functions

This commit is contained in:
John Platts
2022-09-19 13:57:25 -05:00
committed by GitHub
parent a4d2d347e3
commit a7099c039f

View File

@@ -4,10 +4,10 @@
#include <stddef.h> #include <stddef.h>
#include <windows.h> #include <windows.h>
struct NoThrowingWin32HeapAllocT { struct FlatLafNoThrowT {
}; };
constexpr NoThrowingWin32HeapAllocT NoThrowingWin32HeapAlloc{}; constexpr FlatLafNoThrowT FlatLafNoThrow{};
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define FLATLAF_WIN32_ALLOC_INLINE __forceinline #define FLATLAF_WIN32_ALLOC_INLINE __forceinline
@@ -17,28 +17,37 @@ constexpr NoThrowingWin32HeapAllocT NoThrowingWin32HeapAlloc{};
#define FLATLAF_WIN32_ALLOC_INLINE inline #define FLATLAF_WIN32_ALLOC_INLINE inline
#endif #endif
FLATLAF_WIN32_ALLOC_INLINE void* AllocateUsingProcessHeap(size_t cb) noexcept { FLATLAF_WIN32_ALLOC_INLINE void* FlatLafWin32ProcessHeapAlloc(size_t cb) noexcept {
#ifdef _WIN32
return ::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, cb); return ::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, cb);
#else
return ::calloc(cb, 1);
#endif
} }
FLATLAF_WIN32_ALLOC_INLINE void DeleteFromProcessHeap(void* pv) noexcept { FLATLAF_WIN32_ALLOC_INLINE void FlatLafWin32ProcessHeapFree(void* pv) noexcept {
#ifdef _WIN32
if(pv) if(pv)
::HeapFree(::GetProcessHeap(), 0, pv); ::HeapFree(::GetProcessHeap(), 0, pv);
#else
if(pv)
::free(pv);
#endif
} }
FLATLAF_WIN32_ALLOC_INLINE void* operator new(size_t cb, const NoThrowingWin32HeapAllocT& tag) noexcept { FLATLAF_WIN32_ALLOC_INLINE void* operator new(size_t cb, const FlatLafNoThrowT& tag) noexcept {
return AllocateUsingProcessHeap(cb); return FlatLafWin32ProcessHeapAlloc(cb);
} }
FLATLAF_WIN32_ALLOC_INLINE void* operator new[](size_t cb, const NoThrowingWin32HeapAllocT& tag) noexcept { FLATLAF_WIN32_ALLOC_INLINE void* operator new[](size_t cb, const FlatLafNoThrowT& tag) noexcept {
return AllocateUsingProcessHeap(cb); return FlatLafWin32ProcessHeapAlloc(cb);
} }
FLATLAF_WIN32_ALLOC_INLINE void operator delete(void* pv, const NoThrowingWin32HeapAllocT& tag) noexcept { FLATLAF_WIN32_ALLOC_INLINE void operator delete(void* pv, const FlatLafNoThrowT& tag) noexcept {
DeleteFromProcessHeap(pv); FlatLafWin32ProcessHeapFree(pv);
} }
FLATLAF_WIN32_ALLOC_INLINE void operator delete[](void* pv, const NoThrowingWin32HeapAllocT& tag) noexcept { FLATLAF_WIN32_ALLOC_INLINE void operator delete[](void* pv, const FlatLafNoThrowT& tag) noexcept {
DeleteFromProcessHeap(pv); FlatLafWin32ProcessHeapFree(pv);
} }
#endif #endif