Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/util/util_guarded_allocator.h
| Show All 11 Lines | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef __UTIL_GUARDED_ALLOCATOR_H__ | #ifndef __UTIL_GUARDED_ALLOCATOR_H__ | ||||
| #define __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 <memory> | ||||
| #include "util_debug.h" | |||||
| #include "util_types.h" | #include "util_types.h" | ||||
| #ifdef WITH_BLENDER_GUARDEDALLOC | #ifdef WITH_BLENDER_GUARDEDALLOC | ||||
| # include "../../guardedalloc/MEM_guardedalloc.h" | # include "../../guardedalloc/MEM_guardedalloc.h" | ||||
| #endif | #endif | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| Show All 10 Lines | struct rebind { | ||||
| typedef GuardedAllocator<_Tp1> other; | typedef GuardedAllocator<_Tp1> other; | ||||
| }; | }; | ||||
| T *allocate(size_t n, const void *hint = 0) | T *allocate(size_t n, const void *hint = 0) | ||||
| { | { | ||||
| util_guarded_mem_alloc(n * sizeof(T)); | util_guarded_mem_alloc(n * sizeof(T)); | ||||
| #ifdef WITH_BLENDER_GUARDEDALLOC | #ifdef WITH_BLENDER_GUARDEDALLOC | ||||
| (void)hint; | (void)hint; | ||||
| return (T*)MEM_mallocN_aligned(n * sizeof(T), 16, "Cycles Alloc"); | assert(hint == 0); | ||||
| return (T*)MEM_mallocN(n * sizeof(T), "Cycles Alloc"); | |||||
| #else | #else | ||||
| return std::allocator<T>::allocate(n, hint); | return std::allocator<T>::allocate(n, hint); | ||||
| #endif | #endif | ||||
| } | } | ||||
| void deallocate(T *p, size_t n) | void deallocate(T *p, size_t n) | ||||
| { | { | ||||
| util_guarded_mem_free(n * sizeof(T)); | util_guarded_mem_free(n * sizeof(T)); | ||||
| Show All 21 Lines | |||||