From 0bed2be41427a2dbaa10faa7fbea198a0a5c43a8 Mon Sep 17 00:00:00 2001 From: Tomasz Malesinski Date: Sun, 26 Nov 2006 20:56:26 +0000 Subject: FS#6357, patch 3: implemented simple temporary malloc for the Vorbis decoder. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11610 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/Tremor/oggmalloc.c | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 apps/codecs/Tremor/oggmalloc.c (limited to 'apps/codecs/Tremor/oggmalloc.c') diff --git a/apps/codecs/Tremor/oggmalloc.c b/apps/codecs/Tremor/oggmalloc.c new file mode 100644 index 0000000000..eae3d3f1ee --- /dev/null +++ b/apps/codecs/Tremor/oggmalloc.c @@ -0,0 +1,71 @@ +#include + +static unsigned char *mallocbuf; +static long bufsize, tmp_ptr, mem_ptr; + +void ogg_malloc_init(void) +{ + mallocbuf = (unsigned char *)ci->get_codec_memory((size_t *)&bufsize); + tmp_ptr = bufsize & ~3; + mem_ptr = 0; +} + +void *ogg_malloc(size_t size) +{ + void* x; + + if (mem_ptr + (long)size > tmp_ptr) + return NULL; + + x = &mallocbuf[mem_ptr]; + mem_ptr += (size + 3) & ~3; /* Keep memory 32-bit aligned */ + + return x; +} + +void *ogg_tmpmalloc(size_t size) +{ + if (mem_ptr + (long)size > tmp_ptr) + return NULL; + + tmp_ptr -= (size + 3) & ~3; + return &mallocbuf[tmp_ptr]; +} + +void *ogg_calloc(size_t nmemb, size_t size) +{ + void *x; + x = ogg_malloc(nmemb * size); + if (x == NULL) + return NULL; + ci->memset(x, 0, nmemb * size); + return x; +} + +void *ogg_tmpcalloc(size_t nmemb, size_t size) +{ + void *x; + x = ogg_tmpmalloc(nmemb * size); + if (x == NULL) + return NULL; + ci->memset(x, 0, nmemb * size); + return x; +} + +void *ogg_realloc(void *ptr, size_t size) +{ + void *x; + (void)ptr; + x = ogg_malloc(size); + return x; +} + +long ogg_tmpmalloc_pos(void) +{ + return tmp_ptr; +} + +void ogg_tmpmalloc_free(long pos) +{ + tmp_ptr = pos; +} -- cgit v1.2.3