From 21385eb4ec03ff07559fbf73722955d39c77bba8 Mon Sep 17 00:00:00 2001 From: Martin Poirier Date: Tue, 10 Nov 2009 21:33:53 +0000 Subject: [PATCH] New function: void MEM_callbackmemlist(void (*func)(void*)); Will call the function passed as argument with all allocated address as parameter. Useful for debuging. --- intern/guardedalloc/MEM_guardedalloc.h | 3 +++ intern/guardedalloc/intern/mallocn.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index 9e3927314d3..74cc365140f 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -102,6 +102,9 @@ extern "C" { * blocks. */ void MEM_printmemlist(void); + /** calls the function on all allocated memory blocks. */ + void MEM_callbackmemlist(void (*func)(void*)); + /** Print statistics about memory usage */ void MEM_printmemlist_stats(void); diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c index ca7f2a4d506..ecf89c894d2 100644 --- a/intern/guardedalloc/intern/mallocn.c +++ b/intern/guardedalloc/intern/mallocn.c @@ -460,6 +460,24 @@ static void MEM_printmemlist_internal( int pydict ) mem_unlock_thread(); } +void MEM_callbackmemlist(void (*func)(void*)) { + MemHead *membl; + + mem_lock_thread(); + + membl = membase->first; + if (membl) membl = MEMNEXT(membl); + + while(membl) { + func(membl+1); + if(membl->next) + membl= MEMNEXT(membl->next); + else break; + } + + mem_unlock_thread(); +} + void MEM_printmemlist( void ) { MEM_printmemlist_internal(0); }