diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-01 23:04:25 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-03 18:55:23 +0200 |
commit | 43f1c8080ae209f41b95a9a390f0596c454b30d9 (patch) | |
tree | 3d9844d5670e94789b1b9c57f4046e724fed9aa1 /py/malloc.c | |
parent | 4b57fac1c8080f30c09156a99463544b3242d4ff (diff) | |
download | micropython-43f1c8080ae209f41b95a9a390f0596c454b30d9.tar.gz micropython-43f1c8080ae209f41b95a9a390f0596c454b30d9.zip |
m_realloc: Account only allocation size difference in total_bytes_allocated.
Diffstat (limited to 'py/malloc.c')
-rw-r--r-- | py/malloc.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/py/malloc.c b/py/malloc.c index c65d38a968..a94edd3fe9 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -41,7 +41,12 @@ void *m_realloc(void *ptr, int old_num_bytes, int new_num_bytes) { printf("could not allocate memory, reallocating %d bytes\n", new_num_bytes); return NULL; } - total_bytes_allocated += new_num_bytes; + // At first thought, "Total bytes allocated" should only grow, + // after all, it's *total*. But consider for example 2K block + // 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; return ptr; } |