## camel-mempool

camel-mempool

## Functions

CamelMemPool * | camel_mempool_new ()
gpointer | camel_mempool_alloc ()
gchar * | camel_mempool_strdup ()
void | camel_mempool_flush ()
void | camel_mempool_destroy ()

## Types and Values

enum | CamelMemPoolFlags
| CamelMemPool

## 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.

[skip]

#### 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. |

#### Returns

a newly allocated CamelMemPool.

[transfer full]

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.

[skip]

#### Parameters

pool | a CamelMemPool |
size | requested size to allocate |

Since: 2.32

### camel_mempool_strdup ()

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

[skip]

#### 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.

[skip]

#### 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.

[skip]

#### 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