summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bx/src/allocator.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bx/src/allocator.cpp')
-rw-r--r--3rdparty/bx/src/allocator.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/3rdparty/bx/src/allocator.cpp b/3rdparty/bx/src/allocator.cpp
new file mode 100644
index 00000000000..e3b5b37c826
--- /dev/null
+++ b/3rdparty/bx/src/allocator.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ */
+
+#include "bx_p.h"
+#include <bx/allocator.h>
+
+#include <malloc.h>
+
+#ifndef BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT
+# define BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT 8
+#endif // BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT
+
+namespace bx
+{
+ DefaultAllocator::DefaultAllocator()
+ {
+ }
+
+ DefaultAllocator::~DefaultAllocator()
+ {
+ }
+
+ void* DefaultAllocator::realloc(void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line)
+ {
+ if (0 == _size)
+ {
+ if (NULL != _ptr)
+ {
+ if (BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT >= _align)
+ {
+ ::free(_ptr);
+ return NULL;
+ }
+
+# if BX_COMPILER_MSVC
+ BX_UNUSED(_file, _line);
+ _aligned_free(_ptr);
+# else
+ bx::alignedFree(this, _ptr, _align, _file, _line);
+# endif // BX_
+ }
+
+ return NULL;
+ }
+ else if (NULL == _ptr)
+ {
+ if (BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT >= _align)
+ {
+ return ::malloc(_size);
+ }
+
+# if BX_COMPILER_MSVC
+ BX_UNUSED(_file, _line);
+ return _aligned_malloc(_size, _align);
+# else
+ return bx::alignedAlloc(this, _size, _align, _file, _line);
+# endif // BX_
+ }
+
+ if (BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT >= _align)
+ {
+ return ::realloc(_ptr, _size);
+ }
+
+# if BX_COMPILER_MSVC
+ BX_UNUSED(_file, _line);
+ return _aligned_realloc(_ptr, _size, _align);
+# else
+ return bx::alignedRealloc(this, _ptr, _size, _align, _file, _line);
+# endif // BX_
+ }
+
+} // namespace bx