• R/O
  • SSH
  • HTTPS

eirrepo: Commit


Commit MetaInfo

Revision182 (tree)
Time2018-12-31 05:28:49
Authorquiret

Log Message

- added TemplateMemTransalloc function that mimics CRT realloc but is not as effizient as it is

Change Summary

Incremental Difference

--- common/sdk/eirutils.h (revision 181)
+++ common/sdk/eirutils.h (revision 182)
@@ -16,6 +16,7 @@
1616 #include <algorithm>
1717 #include <type_traits>
1818
19+#include <cstddef>
1920 #include <malloc.h>
2021
2122 #include "MacroUtils.h"
@@ -310,4 +311,44 @@
310311 }
311312 };
312313
314+// Not really realloc() but very similar.
315+template <typename allocatorType>
316+AINLINE void* TemplateMemTransalloc( allocatorType& memAlloc, void *refPtr, void *memPtr, size_t oldSize, size_t newSize, size_t alignment = sizeof(std::max_align_t) )
317+{
318+ if ( newSize == 0 )
319+ {
320+ if ( memPtr )
321+ {
322+ memAlloc.Free( refPtr, memPtr );
323+ }
324+
325+ return nullptr;
326+ }
327+
328+ if ( memPtr == nullptr )
329+ {
330+ return memAlloc.Allocate( refPtr, newSize, alignment );
331+ }
332+
333+ bool couldResize = memAlloc.Resize( refPtr, memPtr, newSize );
334+
335+ if ( couldResize )
336+ {
337+ return memPtr;
338+ }
339+
340+ void *newMemPtr = memAlloc.Allocate( refPtr, newSize, alignment );
341+
342+ if ( newMemPtr == nullptr )
343+ {
344+ return nullptr;
345+ }
346+
347+ memcpy( newMemPtr, memPtr, oldSize );
348+
349+ memAlloc.Free( refPtr, memPtr );
350+
351+ return newMemPtr;
352+}
353+
313354 #endif //_EIR_COMMON_SDK_UTILITIES_
\ No newline at end of file
Show on old repository browser