diff options
author | Tomasz Malesinski <tomal@rockbox.org> | 2006-11-26 20:56:26 +0000 |
---|---|---|
committer | Tomasz Malesinski <tomal@rockbox.org> | 2006-11-26 20:56:26 +0000 |
commit | 0bed2be41427a2dbaa10faa7fbea198a0a5c43a8 (patch) | |
tree | 2685d669b2fad93d6bc0a89f17476d93ca49831b /apps/codecs/Tremor/oggmalloc.c | |
parent | 0a0c3f97631f4fbc37db7890196a3bbaa910d7b7 (diff) | |
download | rockbox-0bed2be41427a2dbaa10faa7fbea198a0a5c43a8.tar.gz rockbox-0bed2be41427a2dbaa10faa7fbea198a0a5c43a8.zip |
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
Diffstat (limited to 'apps/codecs/Tremor/oggmalloc.c')
-rw-r--r-- | apps/codecs/Tremor/oggmalloc.c | 71 |
1 files changed, 71 insertions, 0 deletions
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 @@ | |||
1 | #include <os_types.h> | ||
2 | |||
3 | static unsigned char *mallocbuf; | ||
4 | static long bufsize, tmp_ptr, mem_ptr; | ||
5 | |||
6 | void ogg_malloc_init(void) | ||
7 | { | ||
8 | mallocbuf = (unsigned char *)ci->get_codec_memory((size_t *)&bufsize); | ||
9 | tmp_ptr = bufsize & ~3; | ||
10 | mem_ptr = 0; | ||
11 | } | ||
12 | |||
13 | void *ogg_malloc(size_t size) | ||
14 | { | ||
15 | void* x; | ||
16 | |||
17 | if (mem_ptr + (long)size > tmp_ptr) | ||
18 | return NULL; | ||
19 | |||
20 | x = &mallocbuf[mem_ptr]; | ||
21 | mem_ptr += (size + 3) & ~3; /* Keep memory 32-bit aligned */ | ||
22 | |||
23 | return x; | ||
24 | } | ||
25 | |||
26 | void *ogg_tmpmalloc(size_t size) | ||
27 | { | ||
28 | if (mem_ptr + (long)size > tmp_ptr) | ||
29 | return NULL; | ||
30 | |||
31 | tmp_ptr -= (size + 3) & ~3; | ||
32 | return &mallocbuf[tmp_ptr]; | ||
33 | } | ||
34 | |||
35 | void *ogg_calloc(size_t nmemb, size_t size) | ||
36 | { | ||
37 | void *x; | ||
38 | x = ogg_malloc(nmemb * size); | ||
39 | if (x == NULL) | ||
40 | return NULL; | ||
41 | ci->memset(x, 0, nmemb * size); | ||
42 | return x; | ||
43 | } | ||
44 | |||
45 | void *ogg_tmpcalloc(size_t nmemb, size_t size) | ||
46 | { | ||
47 | void *x; | ||
48 | x = ogg_tmpmalloc(nmemb * size); | ||
49 | if (x == NULL) | ||
50 | return NULL; | ||
51 | ci->memset(x, 0, nmemb * size); | ||
52 | return x; | ||
53 | } | ||
54 | |||
55 | void *ogg_realloc(void *ptr, size_t size) | ||
56 | { | ||
57 | void *x; | ||
58 | (void)ptr; | ||
59 | x = ogg_malloc(size); | ||
60 | return x; | ||
61 | } | ||
62 | |||
63 | long ogg_tmpmalloc_pos(void) | ||
64 | { | ||
65 | return tmp_ptr; | ||
66 | } | ||
67 | |||
68 | void ogg_tmpmalloc_free(long pos) | ||
69 | { | ||
70 | tmp_ptr = pos; | ||
71 | } | ||