summaryrefslogtreecommitdiffstats
path: root/source/core/slang-allocator.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-05-31 17:20:37 -0400
committerGitHub <noreply@github.com>2019-05-31 17:20:37 -0400
commit6cbc3929a54d37bd23cb5efa8e3320ba02f78b2f (patch)
tree5a23cb47782e9e2a77762c90dd35da1005eba8d0 /source/core/slang-allocator.h
parentb81ff3ef968d1cc4e954b31a1812b3c391d17b02 (diff)
Use slang- prefix on slang compiler and core source (#973)
* Prefixing source files in source/slang with slang- * Prefix source in source/slang with slang- prefix. * Rename core source files with slang- prefix. * Update project files. * Fix problems from automatic merge.
Diffstat (limited to 'source/core/slang-allocator.h')
-rw-r--r--source/core/slang-allocator.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/source/core/slang-allocator.h b/source/core/slang-allocator.h
new file mode 100644
index 000000000..481f8810f
--- /dev/null
+++ b/source/core/slang-allocator.h
@@ -0,0 +1,64 @@
+#ifndef SLANG_CORE_ALLOCATOR_H
+#define SLANG_CORE_ALLOCATOR_H
+
+#include <stdlib.h>
+#ifdef _MSC_VER
+# include <malloc.h>
+#endif
+
+namespace Slang
+{
+ inline void* alignedAllocate(size_t size, size_t alignment)
+ {
+#ifdef _MSC_VER
+ return _aligned_malloc(size, alignment);
+#elif defined(__CYGWIN__)
+ return aligned_alloc(alignment, size);
+#else
+ void * rs = 0;
+ int succ = posix_memalign(&rs, alignment, size);
+ if (succ!=0)
+ rs = 0;
+ return rs;
+#endif
+ }
+
+ inline void alignedDeallocate(void* ptr)
+ {
+#ifdef _MSC_VER
+ _aligned_free(ptr);
+#else
+ free(ptr);
+#endif
+ }
+
+ class StandardAllocator
+ {
+ public:
+ // not really called
+ void* allocate(size_t size)
+ {
+ return ::malloc(size);
+ }
+ void deallocate(void * ptr)
+ {
+ return ::free(ptr);
+ }
+ };
+
+ template<int ALIGNMENT>
+ class AlignedAllocator
+ {
+ public:
+ void* allocate(size_t size)
+ {
+ return alignedAllocate(size, ALIGNMENT);
+ }
+ void deallocate(void * ptr)
+ {
+ return alignedDeallocate(ptr);
+ }
+ };
+}
+
+#endif