diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-03-30 11:46:56 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-03-31 11:06:21 +0300 |
commit | 0b6b094a8c6ffc19730294723c9e305f18d1182b (patch) | |
tree | 356a69c820e2f3e4e63a17353b7263217d3e2e97 /intern/cycles/util/util_vector.h | |
parent | bd68a25505ac6cb570f695edb7567a472d4ad208 (diff) |
Cycles: Aligned vector was not covered by guarded stat
This was making stats printed by the logging being wrong: they did not
include such memory as BVH storage.
Diffstat (limited to 'intern/cycles/util/util_vector.h')
-rw-r--r-- | intern/cycles/util/util_vector.h | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/intern/cycles/util/util_vector.h b/intern/cycles/util/util_vector.h index 9f9e69cda52..d573939d72a 100644 --- a/intern/cycles/util/util_vector.h +++ b/intern/cycles/util/util_vector.h @@ -107,7 +107,7 @@ public: capacity = 0; } else { - data = (T*)util_aligned_malloc(sizeof(T)*newsize, alignment); + data = mem_allocate(newsize); datasize = newsize; capacity = datasize; } @@ -126,7 +126,7 @@ public: capacity = 0; } else { - data = (T*)util_aligned_malloc(sizeof(T)*from.datasize, alignment); + data = mem_allocate(from.datasize); memcpy(data, from.data, from.datasize*sizeof(T)); datasize = from.datasize; capacity = datasize; @@ -142,7 +142,7 @@ public: data = NULL; if(datasize > 0) { - data = (T*)util_aligned_malloc(sizeof(T)*datasize, alignment); + data = mem_allocate(datasize); memcpy(data, &from[0], datasize*sizeof(T)); } @@ -151,7 +151,7 @@ public: ~array() { - util_aligned_free(data); + mem_free(data, capacity); } T* resize(size_t newsize) @@ -161,15 +161,15 @@ public: } else if(newsize != datasize) { if(newsize > capacity) { - T *newdata = (T*)util_aligned_malloc(sizeof(T)*newsize, alignment); + T *newdata = mem_allocate(newsize); if(newdata == NULL) { /* Allocation failed, likely out of memory. */ clear(); return NULL; } - else if(data) { + else if(data != NULL) { memcpy(newdata, data, ((datasize < newsize)? datasize: newsize)*sizeof(T)); - util_aligned_free(data); + mem_free(data, capacity); } data = newdata; capacity = newsize; @@ -182,7 +182,7 @@ public: void clear() { if(data != NULL) { - util_aligned_free(data); + mem_free(data, capacity); data = NULL; } datasize = 0; @@ -202,10 +202,10 @@ public: void reserve(size_t newcapacity) { if(newcapacity > capacity) { - T *newdata = (T*)util_aligned_malloc(sizeof(T)*newcapacity, alignment); + T *newdata = mem_allocate(newcapacity); if(data) { memcpy(newdata, data, ((datasize < newcapacity)? datasize: newcapacity)*sizeof(T)); - util_aligned_free(data); + mem_free(data, capacity); } data = newdata; capacity = newcapacity; @@ -213,6 +213,23 @@ public: } protected: + inline T* mem_allocate(size_t N) + { + T *mem = (T*)util_aligned_malloc(sizeof(T)*N, alignment); + if(mem != NULL) { + util_guarded_mem_alloc(sizeof(T)*N); + } + return mem; + } + + inline void mem_free(T *mem, size_t N) + { + if(mem != NULL) { + util_guarded_mem_free(sizeof(T)*N); + util_aligned_free(mem); + } + } + T *data; size_t datasize; size_t capacity; |