summaryrefslogtreecommitdiff
path: root/apps/plugins/imageviewer/jpegp/mempool.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/imageviewer/jpegp/mempool.c')
-rw-r--r--apps/plugins/imageviewer/jpegp/mempool.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/apps/plugins/imageviewer/jpegp/mempool.c b/apps/plugins/imageviewer/jpegp/mempool.c
new file mode 100644
index 0000000000..f777ff230a
--- /dev/null
+++ b/apps/plugins/imageviewer/jpegp/mempool.c
@@ -0,0 +1,50 @@
1#include <inttypes.h>
2#include "plugin.h"
3
4static unsigned char *mem_pool;
5static unsigned char *mem_pool_start;
6static size_t memory_size;
7
8extern void *malloc(size_t size)
9{
10 if (size > memory_size)
11 return NULL;
12
13 memory_size -= size;
14 unsigned char* ptr = mem_pool;
15
16 mem_pool+= size;
17 return ptr;
18}
19
20extern void *calloc(size_t nelem, size_t elem_size)
21{
22 unsigned char* ptr = malloc(nelem*elem_size);
23 if (!ptr)
24 return NULL;
25 rb->memset(ptr, 0, nelem*elem_size);
26 return ptr;
27}
28
29extern void init_mem_pool(const unsigned char *buf, const ssize_t buf_size)
30{
31 //TODO: do we need this alignment? (copied from gif lib)
32 unsigned char *memory_max;
33
34 /* align buffer */
35 mem_pool_start = mem_pool = (unsigned char *)((intptr_t)(buf + 3) & ~3);
36 memory_max = (unsigned char *)((intptr_t)(mem_pool + buf_size) & ~3);
37 memory_size = memory_max - mem_pool;
38}
39
40extern ssize_t freeze_mem_pool(void)
41{
42 mem_pool_start = mem_pool;
43 return memory_size;
44}
45
46extern void clear_mem_pool(void)
47{
48 memory_size += mem_pool - mem_pool_start;
49 mem_pool = mem_pool_start;
50} \ No newline at end of file