mempool-alloconly.c revision 65343441df458299bce0bfb8b59a0e0b060564b0
/* Copyright (c) 2002-2003 Timo Sirainen */
/* @UNSAFE: whole file */
#include "lib.h"
#include "mempool.h"
#include <stdlib.h>
#ifdef HAVE_GC_GC_H
# include <gc.h>
#endif
#define MAX_ALLOC_SIZE SSIZE_T_MAX
struct alloconly_pool {
int refcount;
struct pool_block *block;
#ifdef DEBUG
const char *name;
#endif
};
struct pool_block {
struct pool_block *prev;
/* unsigned char data[]; */
};
#define POOL_BLOCK_DATA(block) \
((char *) (block) + SIZEOF_POOLBLOCK)
static struct pool static_alloconly_pool = {
TRUE,
};
{
#ifdef DEBUG
#endif
/* create a fake alloconly_pool so we can call block_alloc() */
/* now allocate the actual alloconly_pool from the created block */
#ifdef DEBUG
#endif
/* set base_size so p_clear() doesn't trash alloconly_pool structure. */
}
{
void *block;
/* destroy all but the last block */
/* destroy the last block */
#ifdef DEBUG
#endif
#ifndef USE_GC
#endif
}
{
#ifdef DEBUG
#else
return "alloconly";
#endif
}
{
}
{
}
{
struct pool_block *block;
/* each block is at least twice the size of the previous one */
#ifdef DEBUG
#endif
}
#ifndef USE_GC
#else
#endif
}
{
void *mem;
/* we need a new block */
}
return mem;
}
{
/* we can free only the last allocation */
}
}
{
/* see if we want to grow the memory we allocated last */
/* yeah, see if we can grow */
/* just shrink the available size */
return TRUE;
}
}
return FALSE;
}
{
unsigned char *new_mem;
return mem;
/* see if we can directly grow it */
/* slow way - allocate + copy */
}
return mem;
}
{
struct pool_block *block;
/* destroy all blocks but the oldest, which contains the
struct alloconly_pool allocation. */
#ifdef DEBUG
#endif
#ifndef USE_GC
#endif
}
/* clear the first block */
}
{
}