Fixed Size Allocation Pools

Name

cyg_mempool_fix_create, cyg_mempool_fix_delete, cyg_mempool_fix_alloc, cyg_mempool_fix_timed_alloc, cyg_mempool_fix_try_alloc, cyg_mempool_fix_free, cyg_mempool_fix_waiting, cyg_mempool_fix_get_info -- Fixed Size Allocation Pools

Synopsis

#include <cyg/kernel/kapi.h>
        

void cyg_mempool_fix_create(void* base, cyg_uint32 size, cyg_uint32 blocksize, cyg_handle_t* fixpool, cyg_mempool_fix* fix);

void cyg_mempool_fix_delete(cyg_handle_t fixpool);

void* cyg_mempool_fix_alloc(cyg_handle_t fixpool);

void* cyg_mempool_fix_timed_alloc(cyg_handle_t fixpool, cyg_tick_count_t abstime);

void* cyg_mempool_fix_try_alloc(cyg_handle_t fixpool);

void cyg_mempool_fix_free(cyg_handle_t fixpool, void* p);

cyg_bool_t cyg_mempool_fix_waiting(cyg_handle_t fixpool);

void cyg_mempool_fix_get_info(cyg_handle_t fixpool, cyg_mempool_info* info);

Description

The fixed size memory pool functions are used for allocating blocks of the same size. The allocation and free functions are more efficient than the variable size pools, but are naturally limited to being only able to allocate blocks of a sized size. Before memory can be allocated the pool must first be created by calling cyg_mempool_fix_create(). The parameter base is a point to the bottom of the memory area to be used by the pool and size is the size of the memory area in bytes. blocksize indicates the size of each allocation in bytes. The function also takes a pointer to a cyg_mempool_fix data structure which is typically statically allocated, and may be part of a larger data structure. It should be noted that some memory is take from the pool for book keeping purposes. If a memory pool is no longer required and there are not threads waiting to allocate memory from it, it can be destroyed with cyg_mempool_fix_delete().

Memory can be allocated from the pool using a number of functions. They all take the paramterfixpoolwhich indicates which pool should be used. cyg_mempool_fix_alloc() will block until the memory becomes available. cyg_mempool_tryalloc()will try not block if no memory is available and will return NULL. Otherwise a pointer to the allocated memory will be returned. cyg_mempool_fix_timed_alloc() will block if memory is not available and wait for memory to become available until the timeabstime is reached. It will then return NULL.

Allocated memory can be freed using the function cyg_mempool_fix_free().

Lastly it is possible to query information about the pool using the function cyg_mempool_fix_get_info(). This takes a pointer to the structure cyg_mempool_info which is:

typedef struct {
    cyg_int32 totalmem;
    cyg_int32 freemem;
    void      *base;
    cyg_int32 size;
    cyg_int32 blocksize;
    cyg_int32 maxfree;
} cyg_mempool_info;