aboutsummaryrefslogtreecommitdiff
path: root/py/malloc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-29 20:33:20 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-29 20:33:20 +0000
commit2d15c1216ddad8ee603106fd86ad36baf2d40ff8 (patch)
tree8403af099522fe40dc74ebefe4711956526cbfd5 /py/malloc.c
parentd0691ccaec37b367892a3cc924ee5eed24288b38 (diff)
stm: Add optional memory debugging output.
Diffstat (limited to 'py/malloc.c')
-rw-r--r--py/malloc.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/py/malloc.c b/py/malloc.c
index 4f01dc63f..a2c55eb06 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -4,6 +4,12 @@
#include "misc.h"
#include "mpconfig.h"
+#if 0 // print debugging info
+#define DEBUG_printf(args...) printf(args)
+#else // don't print debugging info
+#define DEBUG_printf(args...) (void)0
+#endif
+
#if MICROPY_MEM_STATS
static int total_bytes_allocated = 0;
static int current_bytes_allocated = 0;
@@ -26,6 +32,7 @@ void *m_malloc(int num_bytes) {
current_bytes_allocated += num_bytes;
UPDATE_PEAK();
#endif
+ DEBUG_printf("malloc %d : %p\n", num_bytes, ptr);
return ptr;
}
@@ -43,6 +50,7 @@ void *m_malloc0(int num_bytes) {
current_bytes_allocated += num_bytes;
UPDATE_PEAK();
#endif
+ DEBUG_printf("malloc0 %d : %p\n", num_bytes, ptr);
return ptr;
}
@@ -67,6 +75,7 @@ void *m_realloc(void *ptr, int old_num_bytes, int new_num_bytes) {
current_bytes_allocated += diff;
UPDATE_PEAK();
#endif
+ DEBUG_printf("realloc %d, %d : %p\n", old_num_bytes, new_num_bytes, ptr);
return ptr;
}
@@ -77,6 +86,7 @@ void m_free(void *ptr, int num_bytes) {
#if MICROPY_MEM_STATS
current_bytes_allocated -= num_bytes;
#endif
+ DEBUG_printf("free %p, %d\n", ptr, num_bytes);
}
int m_get_total_bytes_allocated(void) {