## camel-mempool camel-mempool |

## Synopsis

                        CamelMemPool;
    enum                CamelMemPoolFlags;
    CamelMemPool *      camel_mempool_new                   (gint blocksize,
                                                             gint threshold,
                                                             CamelMemPoolFlags flags);
    gpointer            camel_mempool_alloc                 (CamelMemPool *pool,
                                                             gint size);
    gchar *             camel_mempool_strdup                (CamelMemPool *pool,
                                                             const gchar *str);
    void                camel_mempool_flush                 (CamelMemPool *pool,
                                                             gint freeall);
    void                camel_mempool_destroy               (CamelMemPool *pool);

## Description

## Details

### CamelMemPool

    typedef struct _CamelMemPool CamelMemPool;

Since 2.32

### enum CamelMemPoolFlags

    typedef enum {
    	CAMEL_MEMPOOL_ALIGN_STRUCT,
    	CAMEL_MEMPOOL_ALIGN_WORD,
    	CAMEL_MEMPOOL_ALIGN_BYTE,
    	CAMEL_MEMPOOL_ALIGN_MASK = 0x3
    } CamelMemPoolFlags;

`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

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

`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 : |

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.

`pool` : | a CamelMemPool
Returns : |

Since 2.32

### camel_mempool_strdup ()

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

`pool` : | a CamelMemPool
Returns : |

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.

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

`pool` : | a CamelMemPool

Since 2.32