#include <glib.h>
Go to the source code of this file.
Data Structures | |
struct | zone |
Zone structure. More... | |
Defines | |
#define | ZALLOC_ALIGNBYTES MEM_ALIGNBYTES |
#define | ZALLOC_MASK (ZALLOC_ALIGNBYTES - 1) |
#define | zalloc_round(s) ((gulong) (((gulong) (s) + ZALLOC_MASK) & ~ZALLOC_MASK)) |
#define | zcount(z) ((z)->zn_cnt) /**< Amount of allocated blocks */ |
Amount of allocated blocks. | |
Typedefs | |
typedef zone | zone_t |
Functions | |
zone_t * | zcreate (gint, gint) |
Create a new zone able to hold items of 'size' bytes. | |
zone_t * | zget (gint, gint) |
Get a zone suitable for allocating blocks 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. | |
gpointer | zalloc (zone_t *) |
Allcate memory with fixed size blocks (zone allocation). | |
void | zfree (zone_t *, gpointer) |
Return block to its zone, hence freeing it. |
|
|
|
|
|
|
|
Amount of allocated blocks.
|
|
|
|
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. |