2
|
1 |
#include <stdio.h>
|
|
2 |
#include <stdlib.h>
|
|
3 |
#include "dictre.h"
|
|
4 |
|
|
5 |
static int given = 0;
|
|
6 |
static int sysallocated = 0;
|
|
7 |
static void *base = 0;
|
|
8 |
|
|
9 |
enum {
|
|
10 |
STEP = 5*1024*1024
|
|
11 |
};
|
|
12 |
|
|
13 |
void * fastmalloc(int newsize)
|
|
14 |
{
|
|
15 |
void *outptr;
|
5
|
16 |
int old_given = given;
|
2
|
17 |
|
|
18 |
given += newsize;
|
|
19 |
|
|
20 |
if (given > sysallocated)
|
|
21 |
{
|
|
22 |
if (STEP > newsize)
|
|
23 |
{
|
|
24 |
base = realloc(base, STEP);
|
|
25 |
sysallocated += STEP;
|
|
26 |
}
|
|
27 |
else
|
|
28 |
{
|
|
29 |
base = realloc(base, newsize);
|
|
30 |
sysallocated += newsize;
|
|
31 |
}
|
|
32 |
}
|
|
33 |
|
5
|
34 |
outptr = base + old_given;
|
|
35 |
|
2
|
36 |
return outptr;
|
|
37 |
}
|