]> git.tdb.fi Git - gldbg.git/blob - source/tmpalloc.c
56d955e5a3dd73966b1ed1d13927ce3652e34737
[gldbg.git] / source / tmpalloc.c
1 /* $Id$
2
3 This file is part of gldbg
4 Copyright © 2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
6 */
7
8 #include <stdlib.h>
9 #include "tmpalloc.h"
10
11 void *buffer = 0;
12 unsigned buf_size = 8192;
13 unsigned offset = 0;
14
15 void *tmpalloc(unsigned size)
16 {
17         void *ptr;
18         if(!buffer)
19                 buffer = malloc(buf_size);
20         if(offset+size>buf_size)
21                 offset = 0;
22         ptr = (char *)buffer+offset;
23         offset += size;
24         return ptr;
25 }
26
27 void tmpfree()
28 {
29         free(buffer);
30         buffer = 0;
31         offset = 0;
32 }