#include "common.h"
#include "zalloc.h"
#include "override.h"
Data Structures | |
struct | subzone |
Extra allocated zones. More... | |
Defines | |
#define | DEFAULT_HINT 128 /**< Default amount of blocks in a zone */ |
Default amount of blocks in a zone. | |
#define | MAX_ZONE_SIZE 16384 /**< Maximum zone size */ |
Maximum zone size. | |
Functions | |
RCSID ("$Id:zalloc.c, v 1.8 2005/09/10 10:10:36 daichik Exp $") | |
void | zn_cram (zone_t *, gchar *, gint) |
Cram a new zone in chunk. | |
zone * | zn_create (zone_t *, gint, gint) |
Create a new zone able to hold items of 'size' bytes. | |
gchar ** | zn_extend (zone_t *) |
Extend zone by allocating a new zone chunk. | |
gpointer | zalloc (zone_t *zone) |
Allcate memory with fixed size blocks (zone allocation). | |
void | zfree (zone_t *zone, gpointer ptr) |
Return block to its zone, hence freeing it. | |
zone_t * | zcreate (gint size, gint hint) |
Create a new zone able to hold items of 'size' bytes. | |
void | zdestroy (zone_t *zone) |
Destroy a zone chunk by releasing its memory to the system if possible, converting it into a malloc chunk otherwise. | |
zone_t * | zget (gint size, gint hint) |
Get a zone suitable for allocating blocks of 'size' bytes. |
|
Default amount of blocks in a zone.
|
|
Maximum zone size.
|
|
|
|
Allcate memory with fixed size blocks (zone allocation). Returns a pointer to a block containing at least 'size' bytes of memory. It is a fatal error if memory cannot be allocated. A zone is, in its simplest expression, a memory chunk where fix-sized blocks are sliced, all free blocks being chained together via a link written in the first bytes of the block. To allocate a block, the first free block is removed from the list. Freeing is just as easy, since we insert the block at the head of the free list. Zone chunks are linked together to make a bigger pool, where only the first zone descriptor is accurate (i.e. only it has meaningful zn_cnt and zn_free fields). The advantages for allocating from a zone are:
The disadvantages are:
Moreover, periodic calls to the zone gc are needed to collect unused chunks when peak allocations are infrequent or occur at random. < Allocated block |
|
Create a new zone able to hold items of 'size' bytes. Returns NULL if no new zone can be created. The hint argument is to be construed as the average amount of objects that are to be created per zone chunks. That is not the total amount of expected objects of a given type. Leaving it a 0 selects the default hint value. |
|
Destroy a zone chunk by releasing its memory to the system if possible, converting it into a malloc chunk otherwise.
|
|
Return block to its zone, hence freeing it. Previous content of the block is lost. Since a zone consists of blocks with a fixed size, memory fragmentation is not an issue. Therefore, the block is returned to the zone by being inserted at the head of the free list. Warning: returning a block to the wrong zone may lead to disasters. |
|
Get a zone suitable for allocating blocks of 'size' bytes. `hint' represents the desired amount of blocks per subzone. This is mainly intended for external clients who want distinct zones for distinct sizes, yet may share zones for distinct albeit same-sized blocks. For instance, walloc() requests zones for power-of-two sizes and uses zget() to get the zone, instead of zcreate() to maximize sharing. |
|
Cram a new zone in chunk. A zone consists of linked blocks, where the address of the next free block is written in the first bytes of each free block. |
|
Create a new zone able to hold items of 'size' bytes.
|
|
Extend zone by allocating a new zone chunk.
|