diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-02-14 15:29:47 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-02-15 00:01:48 +0300 |
commit | 01067fe51c4f3df06fa6e8744da2344253201ec6 (patch) | |
tree | c96ce2b9839e4f6f63b842c574ca88ef0c0ceb22 /intern/cycles/util/util_vector.h | |
parent | 24976dd29d16ffc176ad0f87246fa98a1da31ccc (diff) |
Cycles: Replace own aligned allocator with system one
This replaces our own implementation of aligned malloc with system calls,
which depends on which operation system you're on.
This is probably really minor noticeable change, but in the same time it
might reduce amount of wasted memory.
Diffstat (limited to 'intern/cycles/util/util_vector.h')
-rw-r--r-- | intern/cycles/util/util_vector.h | 35 |
1 files changed, 8 insertions, 27 deletions
diff --git a/intern/cycles/util/util_vector.h b/intern/cycles/util/util_vector.h index 269fe04a4ae..710b0690256 100644 --- a/intern/cycles/util/util_vector.h +++ b/intern/cycles/util/util_vector.h @@ -22,32 +22,13 @@ #include <string.h> #include <vector> +#include "util_aligned_malloc.h" #include "util_types.h" CCL_NAMESPACE_BEGIN using std::vector; -static inline void *malloc_aligned(size_t size, size_t alignment) -{ - void *data = (void*)malloc(size + sizeof(void*) + alignment - 1); - - union { void *ptr; size_t offset; } u; - u.ptr = (char*)data + sizeof(void*); - u.offset = (u.offset + alignment - 1) & ~(alignment - 1); - *(((void**)u.ptr) - 1) = data; - - return u.ptr; -} - -static inline void free_aligned(void *ptr) -{ - if(ptr) { - void *data = *(((void**)ptr) - 1); - free(data); - } -} - /* Array * * Simplified version of vector, serving multiple purposes: @@ -74,7 +55,7 @@ public: datasize = 0; } else { - data = (T*)malloc_aligned(sizeof(T)*newsize, alignment); + data = (T*)util_aligned_malloc(sizeof(T)*newsize, alignment); datasize = newsize; } } @@ -91,7 +72,7 @@ public: datasize = 0; } else { - data = (T*)malloc_aligned(sizeof(T)*from.datasize, alignment); + data = (T*)util_aligned_malloc(sizeof(T)*from.datasize, alignment); memcpy(data, from.data, from.datasize*sizeof(T)); datasize = from.datasize; } @@ -105,7 +86,7 @@ public: data = NULL; if(datasize > 0) { - data = (T*)malloc_aligned(sizeof(T)*datasize, alignment); + data = (T*)util_aligned_malloc(sizeof(T)*datasize, alignment); memcpy(data, &from[0], datasize*sizeof(T)); } @@ -114,7 +95,7 @@ public: ~array() { - free_aligned(data); + util_aligned_free(data); } void resize(size_t newsize) @@ -123,10 +104,10 @@ public: clear(); } else if(newsize != datasize) { - T *newdata = (T*)malloc_aligned(sizeof(T)*newsize, alignment); + T *newdata = (T*)util_aligned_malloc(sizeof(T)*newsize, alignment); if(data) { memcpy(newdata, data, ((datasize < newsize)? datasize: newsize)*sizeof(T)); - free_aligned(data); + util_aligned_free(data); } data = newdata; @@ -136,7 +117,7 @@ public: void clear() { - free_aligned(data); + util_aligned_free(data); data = NULL; datasize = 0; } |