[Bf-blender-cvs] [0b6b094] master: Cycles: Aligned vector was not covered by guarded stat

Sergey Sharybin noreply at git.blender.org
Thu Mar 31 10:23:21 CEST 2016


Commit: 0b6b094a8c6ffc19730294723c9e305f18d1182b
Author: Sergey Sharybin
Date:   Wed Mar 30 10:46:56 2016 +0200
Branches: master
https://developer.blender.org/rB0b6b094a8c6ffc19730294723c9e305f18d1182b

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.

===================================================================

M	intern/cycles/util/util_vector.h

===================================================================

diff --git a/intern/cycles/util/util_vector.h b/intern/cycles/util/util_vector.h
index 9f9e69c..d573939 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;




More information about the Bf-blender-cvs mailing list