• R/O
  • SSH
  • HTTPS

eirrepo: Commit


Commit MetaInfo

Revision164 (tree)
Time2018-12-12 18:55:34
Authorquiret

Log Message

- added global "CRTHeapAllocator" struct

Change Summary

Incremental Difference

--- common/sdk/eirutils.h (revision 163)
+++ common/sdk/eirutils.h (revision 164)
@@ -16,6 +16,10 @@
1616 #include <algorithm>
1717 #include <type_traits>
1818
19+#ifdef _MSC_VER
20+#include <malloc.h>
21+#endif //_MSC_VER
22+
1923 #include "MacroUtils.h"
2024
2125 namespace eir
@@ -276,4 +280,33 @@
276280 // not happened yet.
277281 };
278282
283+// The basic allocator that links to the CRT.
284+// I was heavy against exposing this but I cannot overcome the static-initialization order in current C++17.
285+struct CRTHeapAllocator
286+{
287+ static AINLINE void* Allocate( void *refPtr, size_t memSize, size_t alignment )
288+ {
289+#ifdef _MSC_VER
290+ return _aligned_malloc( memSize, alignment );
291+#else
292+ return aligned_alloc( alignment, memSize );
293+#endif //_MSC_VER
294+ }
295+
296+ static AINLINE bool Resize( void *refPtr, void *memPtr, size_t newSize )
297+ {
298+ // I cannot believe that Microsoft has not yet added "_aligned_expand".
299+ return false;
300+ }
301+
302+ static AINLINE void Free( void *refPtr, void *memPtr )
303+ {
304+#ifdef _MSC_VER
305+ _aligned_free( memPtr );
306+#else
307+ free( memPtr );
308+#endif //_MSC_VER
309+ }
310+};
311+
279312 #endif //_EIR_COMMON_SDK_UTILITIES_
\ No newline at end of file
Show on old repository browser