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

walloc.h File Reference


Detailed Description

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

Author:
Raphael Manfredi
Date:
2002-2003

#include "common.h"
#include "malloc.h"

Go to the source code of this file.

Defines

#define WFREE_NULL(p, size)

Functions

gpointer walloc (size_t size) WARN_UNUSED_RESULT G_GNUC_MALLOC
 Allocate memory from a zone suitable for the given size.
gpointer walloc0 (size_t size) WARN_UNUSED_RESULT G_GNUC_MALLOC
 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) WARN_UNUSED_RESULT G_GNUC_MALLOC
 Reallocate a block allocated via walloc().
gpointer wcopy (gconstpointer ptr, size_t size) WARN_UNUSED_RESULT G_GNUC_MALLOC
void wdestroy (void)
 Destroy all the zones we allocated so far.


Define Documentation

#define WFREE_NULL p,
size   ) 
 

Value:

G_STMT_START {              \
    if (p) {                \
        wfree(p,size);      \
        p = NULL;           \
    }                       \
} G_STMT_END


Function Documentation

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.

gpointer wcopy gconstpointer  ptr,
size_t  size
[inline, static]
 

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.


Generated on Sat Jun 30 17:53:32 2007 for gtk-gnutella by  doxygen 1.3.9.1