camel-mempool

camel-mempool

Types and Values

Description

Functions

camel_mempool_new ()

CamelMemPool *
camel_mempool_new (gint blocksize,
                   gint threshold,
                   CamelMemPoolFlags flags);

Create a new mempool header. Mempools can be used to efficiently allocate data which can then be freed as a whole.

Mempools can also be used to efficiently allocate arbitrarily aligned data (such as strings) without incurring the space overhead of aligning each allocation (which is not required for strings).

However, each allocation cannot be freed individually, only all or nothing.

Parameters

blocksize

The base blocksize to use for all system alocations.

 

threshold

If the allocation exceeds the threshold, then it is allocated separately and stored in a separate list.

 

flags

Alignment options: CAMEL_MEMPOOL_ALIGN_STRUCT uses native struct alignment, CAMEL_MEMPOOL_ALIGN_WORD aligns to 16 bits (2 bytes), and CAMEL_MEMPOOL_ALIGN_BYTE aligns to the nearest byte. The default is to align to native structures.

 

Since: 2.32


camel_mempool_alloc ()

gpointer
camel_mempool_alloc (CamelMemPool *pool,
                     gint size);

Allocate a new data block in the mempool. Size will be rounded up to the mempool's alignment restrictions before being used.

Parameters

pool

a CamelMemPool

 

Since: 2.32


camel_mempool_strdup ()

gchar *
camel_mempool_strdup (CamelMemPool *pool,
                      const gchar *str);

Parameters

pool

a CamelMemPool

 

Since: 2.32


camel_mempool_flush ()

void
camel_mempool_flush (CamelMemPool *pool,
                     gint freeall);

Flush used memory and mark allocated blocks as free.

If freeall is TRUE, then all allocated blocks are free'd as well. Otherwise only blocks above the threshold are actually freed, and the others are simply marked as empty.

Parameters

pool

a CamelMemPool

 

freeall

free all system allocated blocks as well

 

Since: 2.32


camel_mempool_destroy ()

void
camel_mempool_destroy (CamelMemPool *pool);

Free all memory associated with a mempool.

Parameters

pool

a CamelMemPool

 

Since: 2.32

Types and Values

enum CamelMemPoolFlags

Members

CAMEL_MEMPOOL_ALIGN_STRUCT

Allocate to native structure alignment

 

CAMEL_MEMPOOL_ALIGN_WORD

Allocate to words - 16 bit alignment

 

CAMEL_MEMPOOL_ALIGN_BYTE

Allocate to bytes - 8 bit alignment

 

CAMEL_MEMPOOL_ALIGN_MASK

Which bits determine the alignment information

 

Since: 2.32


CamelMemPool

typedef struct _CamelMemPool CamelMemPool;

Since: 2.32