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.
This commit is contained in:
Sergey Sharybin 2015-02-14 23:26:07 +05:00
parent d0cc1180b0
commit 18937f6fb5

@ -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>() { }