fastmalloc.c
author viric@llimona
Sun, 02 Sep 2007 15:59:31 +0200
changeset 26 700a68421116
parent 5 c87681fff7d3
permissions -rw-r--r--
Adding .hgignore and the ia5test.
#include <stdio.h>
#include <stdlib.h>
#include "dictre.h"

static int given = 0;
static int sysallocated = 0;
static void *base = 0;

enum {
    STEP = 5*1024*1024
};

void * fastmalloc(int newsize)
{
    void *outptr;
    int old_given = given;

    given += newsize;

    if (given > sysallocated)
    {
        if (STEP > newsize)
        {
            base = realloc(base, STEP);
            sysallocated += STEP;
        }
        else
        {
            base = realloc(base, newsize);
            sysallocated += newsize;
        }
    }

    outptr = base + old_given;

    return outptr;
}