Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

walloc.c File Reference


Detailed Description

Explicit-width block allocator, based on zalloc().

Author:
Raphael Manfredi
Date:
2002-2003

#include "common.h"
#include "walloc.h"
#include "zalloc.h"
#include "override.h"

Defines

#define WALLOC_MAX   4096 /**< Passed this size, use malloc() */
 Passed this size, use malloc().

#define WALLOC_CHUNK   4096 /**< Target chunk size for small structs */
 Target chunk size for small structs.

#define WALLOC_MINCOUNT   8 /**< Minimum amount of structs in a chunk */
 Minimum amount of structs in a chunk.

#define WZONE_SIZE   (WALLOC_MAX / ZALLOC_ALIGNBYTES)

Functions

 RCSID ("$Id:walloc.c, v 1.8 2005/09/26 16:51:29 cbiere Exp $")
gpointer walloc (size_t size)
 Allocate memory from a zone suitable for the given size.

gpointer walloc0 (size_t size)
 Same as walloc(), but zeroes the allocated memory before returning.

void wfree (gpointer ptr, size_t size)
 Free a block allocated via walloc().

gpointer wrealloc (gpointer old, size_t old_size, size_t new_size)
 Reallocate a block allocated via walloc().

void wdestroy (void)
 Destroy all the zones we allocated so far.


Variables

zonewzone [WZONE_SIZE]


Define Documentation

#define WALLOC_CHUNK   4096 /**< Target chunk size for small structs */
 

Target chunk size for small structs.

#define WALLOC_MAX   4096 /**< Passed this size, use malloc() */
 

Passed this size, use malloc().

#define WALLOC_MINCOUNT   8 /**< Minimum amount of structs in a chunk */
 

Minimum amount of structs in a chunk.

#define WZONE_SIZE   (WALLOC_MAX / ZALLOC_ALIGNBYTES)
 


Function Documentation

RCSID "$Id:walloc.  c,
v 1.8 2005/09/26 16:51:29 cbiere Exp $" 
 

gpointer walloc size_t  size  ) 
 

Allocate memory from a zone suitable for the given size.

The basics for this algorithm is to allocate from fixed-sized zones, which are multiples of ZALLOC_ALIGNBYTES until WALLOC_MAX (e.g. 8, 16, 24, 40, ...) and to malloc() if size is greater or equal to WALLOC_MAX. Naturally, zones are allocated on demand only.

Returns:
a pointer to the start of the allocated block.

gpointer walloc0 size_t  size  ) 
 

Same as walloc(), but zeroes the allocated memory before returning.

void wdestroy void   ) 
 

Destroy all the zones we allocated so far.

void wfree gpointer  ptr,
size_t  size
 

Free a block allocated via walloc().

The size is used to find the zone from which the block was allocated, or to determine that we actually malloc()'ed it so it gets free()'ed.

gpointer wrealloc gpointer  old,
size_t  old_size,
size_t  new_size
 

Reallocate a block allocated via walloc().

Returns:
new block address.


Variable Documentation

struct zone* wzone[WZONE_SIZE] [static]
 


Generated on Sun Feb 12 10:50:10 2006 for Gtk-Gnutella by doxygen 1.3.6