summaryrefslogtreecommitdiffstats
path: root/source/core/allocator.h
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-06-09 11:34:21 -0700
committerTim Foley <tfoley@nvidia.com>2017-06-09 13:44:59 -0700
commitfcf83dbf9effab3bd98bad2b83b2468b7eb05cfd (patch)
tree41047c94883b86ec085a81597391ce3ef557cd43 /source/core/allocator.h
parent52e8d4b9a27ab0060f874c3a63ab531847be35c0 (diff)
Initial import of code.
Diffstat (limited to 'source/core/allocator.h')
-rw-r--r--source/core/allocator.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/source/core/allocator.h b/source/core/allocator.h
new file mode 100644
index 000000000..d4dfcf5a9
--- /dev/null
+++ b/source/core/allocator.h
@@ -0,0 +1,62 @@
+#ifndef CORE_LIB_ALLOCATOR_H
+#define CORE_LIB_ALLOCATOR_H
+
+#include <stdlib.h>
+
+namespace CoreLib
+{
+ namespace Basic
+ {
+ inline void * AlignedAlloc(size_t size, size_t alignment)
+ {
+#ifdef _MSC_VER
+ return _aligned_malloc(size, alignment);
+#else
+ void * rs = 0;
+ int succ = posix_memalign(&rs, alignment, size);
+ if (succ!=0)
+ rs = 0;
+ return rs;
+#endif
+ }
+
+ inline void AlignedFree(void * ptr)
+ {
+#ifdef _MSC_VER
+ _aligned_free(ptr);
+#else
+ free(ptr);
+#endif
+ }
+
+ class StandardAllocator
+ {
+ public:
+ // not really called
+ void * Alloc(size_t size)
+ {
+ return malloc(size);
+ }
+ void Free(void * ptr)
+ {
+ return free(ptr);
+ }
+ };
+
+ template<int alignment>
+ class AlignedAllocator
+ {
+ public:
+ void * Alloc(size_t size)
+ {
+ return AlignedAlloc(size, alignment);
+ }
+ void Free(void * ptr)
+ {
+ return AlignedFree(ptr);
+ }
+ };
+ }
+}
+
+#endif \ No newline at end of file