[Bf-blender-cvs] [18937f6] master: Cycles: Add ifdef switch to use blender's guardedalloc for vector allocation

Sergey Sharybin noreply at git.blender.org
Sat Feb 14 22:08:51 CET 2015


Commit: 18937f6fb5582f6a11bc3f732ae21d77b0219c39
Author: Sergey Sharybin
Date:   Sat Feb 14 23:26:07 2015 +0500
Branches: master
https://developer.blender.org/rB18937f6fb5582f6a11bc3f732ae21d77b0219c39

Cycles: Add ifdef switch to use blender's guardedalloc for vector allocation

It's actually a bad level call, but it's inside ifdef block and disabled by
default and only intended to be used for development purposes.

Main idea of this change is to combine statistics coming from Cycles and
Blender during scene synchronization step, to see if further changes are
actually reducing memory footprint.

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

M	intern/cycles/util/util_guarded_allocator.h

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

diff --git a/intern/cycles/util/util_guarded_allocator.h b/intern/cycles/util/util_guarded_allocator.h
index 4a7e082..2631994 100644
--- a/intern/cycles/util/util_guarded_allocator.h
+++ b/intern/cycles/util/util_guarded_allocator.h
@@ -17,10 +17,23 @@
 #ifndef __UTIL_GUARDED_ALLOCATOR_H__
 #define __UTIL_GUARDED_ALLOCATOR_H__
 
+/* Define this in order to use Blender's guarded allocator to keep
+ * track of allocated buffers, their sizes and peak memory usage.
+ *
+ * This is usually a bad level call, but it's really handy to keep
+ * track of overall peak memory consumption during the scene
+ * synchronization step.
+ */
+#undef WITH_BLENDER_GUARDEDALLOC
+
 #include <memory>
 
 #include "util_types.h"
 
+#ifdef WITH_BLENDER_GUARDEDALLOC
+#  include "../../guardedalloc/MEM_guardedalloc.h"
+#endif
+
 CCL_NAMESPACE_BEGIN
 
 /* Internal use only. */
@@ -39,13 +52,21 @@ public:
 	T *allocate(size_t n, const void *hint = 0)
 	{
 		util_guarded_mem_alloc(n * sizeof(T));
+#ifdef WITH_BLENDER_GUARDEDALLOC
+		return (T*)MEM_mallocN(n * sizeof(T), "Cycles Alloc");
+#else
 		return std::allocator<T>::allocate(n, hint);
+#endif
 	}
 
 	void deallocate(T *p, size_t n)
 	{
 		util_guarded_mem_free(n * sizeof(T));
-		return std::allocator<T>::deallocate(p, n);
+#ifdef WITH_BLENDER_GUARDEDALLOC
+		MEM_freeN((void*)p);
+#else
+		std::allocator<T>::deallocate(p, n);
+#endif
 	}
 
 	GuardedAllocator() : std::allocator<T>() {  }




More information about the Bf-blender-cvs mailing list