fastmalloc.c
author viric@llimona
Sun, 02 Sep 2007 16:01:27 +0200
changeset 27 153c479aa0bc
parent 5 c87681fff7d3
permissions -rw-r--r--
LEGUMIN kaj aliaj gxisdatigoj.
viric@2
     1
#include <stdio.h>
viric@2
     2
#include <stdlib.h>
viric@2
     3
#include "dictre.h"
viric@2
     4
viric@2
     5
static int given = 0;
viric@2
     6
static int sysallocated = 0;
viric@2
     7
static void *base = 0;
viric@2
     8
viric@2
     9
enum {
viric@2
    10
    STEP = 5*1024*1024
viric@2
    11
};
viric@2
    12
viric@2
    13
void * fastmalloc(int newsize)
viric@2
    14
{
viric@2
    15
    void *outptr;
viric@5
    16
    int old_given = given;
viric@2
    17
viric@2
    18
    given += newsize;
viric@2
    19
viric@2
    20
    if (given > sysallocated)
viric@2
    21
    {
viric@2
    22
        if (STEP > newsize)
viric@2
    23
        {
viric@2
    24
            base = realloc(base, STEP);
viric@2
    25
            sysallocated += STEP;
viric@2
    26
        }
viric@2
    27
        else
viric@2
    28
        {
viric@2
    29
            base = realloc(base, newsize);
viric@2
    30
            sysallocated += newsize;
viric@2
    31
        }
viric@2
    32
    }
viric@2
    33
viric@5
    34
    outptr = base + old_given;
viric@5
    35
viric@2
    36
    return outptr;
viric@2
    37
}