diff options
| author | Jonathan Gordon <rockbox@jdgordon.info> | 2006-10-25 14:30:45 +0000 |
|---|---|---|
| committer | Jonathan Gordon <rockbox@jdgordon.info> | 2006-10-25 14:30:45 +0000 |
| commit | e48a0354093a5c7f26d67f5584dfb2f38f680870 (patch) | |
| tree | aab8d06f6fa3aa8b8bafe3f8e1a33ad6e0db72cb /apps/tagdb/malloc.c | |
| parent | 18755b97c014365387f42ea2acd8e9982982fb00 (diff) | |
| download | rockbox-e48a0354093a5c7f26d67f5584dfb2f38f680870.zip rockbox-e48a0354093a5c7f26d67f5584dfb2f38f680870.tar.gz rockbox-e48a0354093a5c7f26d67f5584dfb2f38f680870.tar.bz2 rockbox-e48a0354093a5c7f26d67f5584dfb2f38f680870.tar.xz | |
remove the old tagdb source, tagcache replaced this a while ago
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11340 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/tagdb/malloc.c')
| -rw-r--r-- | apps/tagdb/malloc.c | 133 |
1 files changed, 0 insertions, 133 deletions
diff --git a/apps/tagdb/malloc.c b/apps/tagdb/malloc.c deleted file mode 100644 index dbc2c5b..0000000 --- a/apps/tagdb/malloc.c +++ /dev/null @@ -1,133 +0,0 @@ -#ifdef HAVE_TAGCACHE -#include "config.h" -#include "malloc.h" - -#undef malloc -#undef free -#undef realloc - -#undef DEBUGF -#define DEBUGF(...) - -#include <stdio.h> -#include <stdlib.h> - -static size_t total=0; -static size_t max_total=0; - -struct size_array { - void *ptr; - size_t size; -} sizes[1000]; -#define NOT_FOUND 1001 -static unsigned long count=0; - -int out_of_memory = 1000000; - -void *do_malloc(size_t size) { - void *ret; - if(total + size > out_of_memory) { - DEBUGF("malloc(%d), total=%d: FAILED: simulating out-of-memory\n", size, total+size); - return NULL; - } - - ret = malloc(size); - if( ret == NULL ) { - DEBUGF("malloc(%d), total=%d FAILED\n", size, total+size); - return NULL; - } else { - total += size; - max_total = ( total > max_total ? total : max_total ); - sizes[count].ptr = ret; - sizes[count].size = size; - DEBUGF("malloc(%d), total=%d OK => 0x%08lx (%lu)\n", size, total, (unsigned long)ret, count); - count++; - if(count == NOT_FOUND) { - fprintf(stderr, "MALLOC MEMORY FULL!!!!!!! FAILING\n"); - free(ret); - count--; - return NULL; - } - return ret; - } -} - -static unsigned long find(void* ptr) { - unsigned long i; - for(i=0; i<count; i++) { - if( ptr == sizes[i].ptr ) { - return i; - } - } - return NOT_FOUND; -} - -void do_free(void *ptr) { - unsigned long i; - - i = find(ptr); - if( i == NOT_FOUND ) { - DEBUGF("free(%08lx) (?) ptr unknown\n", (unsigned long)ptr); - free(ptr); - } else { - total -= sizes[i].size; - DEBUGF("free(%08lx) (%lu, %dbytes) => total=%u\n", (unsigned long)ptr, i, sizes[i].size, total); - free(ptr); - sizes[i].ptr = NULL; // delete - sizes[i].size = 0; - } -} - -void *do_realloc(void *ptr, size_t size) { - void *ret; - unsigned long i; - - if( ptr == NULL ) { - DEBUGF("realloc()=>"); - return do_malloc(size); - } - - i = find(ptr); - - if( i == NOT_FOUND ) { - DEBUGF("realloc(%08lx, %d) (?) ptr unknown ", (unsigned long)ptr, size); - } else { - DEBUGF("realloc(%08lx, %d) (%lu, %dbytes) => total=%d ", (unsigned long)ptr, size, i, sizes[i].size, total+size-sizes[i].size); - } - - if(total + size - sizes[i].size > out_of_memory) { - DEBUGF("FAILED: simulating out-of-memory\n"); - return NULL; - } - - ret = realloc(ptr, size); - if( ret == NULL && size != 0) { // realloc(x, 0) returns NULL, but is valid! - DEBUGF("FAILED\n"); - } else { - total += size - sizes[i].size; - max_total = ( total > max_total ? total : max_total ); - sizes[i].ptr = ret; // update the ptr if realloc changed it - sizes[i].size = size; - DEBUGF("=> %08lx\n", (unsigned long)ret); - } - return ret; -} - -void malloc_stats() { - unsigned long i, j; - - printf("malloc stats:\n"); - printf(" Total number of allocated items: %lu\n", count); - printf(" Current number of allocated items: "); - j=0; - for(i=0; i<count; i++) { - if( sizes[i].ptr != NULL) { - printf("%lu ", i); - j++; - } - } - printf("=> %lu items\n", j); - printf(" Maximum amount of allocated memory: %dbytes\n", max_total); - printf(" Current amount of allocated memory: %dbytes\n", total); -} -#endif |