diff --git a/intern/cycles/util/util_guarded_allocator.h b/intern/cycles/util/util_guarded_allocator.h index 4a7e0825388..263199417c4 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 #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::allocate(n, hint); +#endif } void deallocate(T *p, size_t n) { util_guarded_mem_free(n * sizeof(T)); - return std::allocator::deallocate(p, n); +#ifdef WITH_BLENDER_GUARDEDALLOC + MEM_freeN((void*)p); +#else + std::allocator::deallocate(p, n); +#endif } GuardedAllocator() : std::allocator() { }