aboutsummaryrefslogtreecommitdiff
path: root/py/malloc.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-01 23:15:47 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-03 18:55:23 +0200
commit02de0c57d233bf969ed3971c319a96dd9f998549 (patch)
tree043a92c90c6cd5aa928886ead41ed41b4ce4759f /py/malloc.c
parent43f1c8080ae209f41b95a9a390f0596c454b30d9 (diff)
Add new alloc metric: current_bytes_allocated.
Unlike total_bytes_allocated, this tracks m_free()'s too.
Diffstat (limited to 'py/malloc.c')
-rw-r--r--py/malloc.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/py/malloc.c b/py/malloc.c
index a94edd3fe..13f0a8fc3 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -4,6 +4,7 @@
#include "misc.h"
static int total_bytes_allocated = 0;
+static int current_bytes_allocated = 0;
void *m_malloc(int num_bytes) {
if (num_bytes == 0) {
@@ -15,6 +16,7 @@ void *m_malloc(int num_bytes) {
return NULL;
}
total_bytes_allocated += num_bytes;
+ current_bytes_allocated += num_bytes;
return ptr;
}
@@ -28,6 +30,7 @@ void *m_malloc0(int num_bytes) {
return NULL;
}
total_bytes_allocated += num_bytes;
+ current_bytes_allocated += num_bytes;
return ptr;
}
@@ -46,7 +49,9 @@ void *m_realloc(void *ptr, int old_num_bytes, int new_num_bytes) {
// shrunk to 1K and then grown to 2K again. It's still 2K
// allocated total. If we process only positive increments,
// we'll count 3K.
- total_bytes_allocated += new_num_bytes - old_num_bytes;
+ int diff = new_num_bytes - old_num_bytes;
+ total_bytes_allocated += diff;
+ current_bytes_allocated += diff;
return ptr;
}
@@ -54,8 +59,13 @@ void m_free(void *ptr, int num_bytes) {
if (ptr != NULL) {
free(ptr);
}
+ current_bytes_allocated -= num_bytes;
}
int m_get_total_bytes_allocated(void) {
return total_bytes_allocated;
}
+
+int m_get_current_bytes_allocated(void) {
+ return current_bytes_allocated;
+}