Code Confidencebuild 3.0.0.201402161939

Variable Size Allocation Pools

Name

cyg_mempool_var_create, cyg_mempool_var_delete, cyg_mempool_var_alloc, cyg_mempool_var_timed_alloc, cyg_mempool_var_try_alloc, cyg_mempool_var_free, cyg_mempool_var_waiting, cyg_mempool_var_get_info -- Variable Size Allocation Pools

Synopsis

#include <cyg/kernel/kapi.h>
        

void cyg_mempool_var_create(void* base, cyg_uint32 size, cyg_handle_t* varpool, cyg_mempool_var* var);

void cyg_mempool_var_delete(cyg_handle_t varpool);

void* cyg_mempool_var_alloc(cyg_handle_t varpool, cyg_uint32 size);

void* cyg_mempool_var_timed_alloc(cyg_handle_t varpool, cyg_uint32 size, cyg_tick_count_t abstime);

void* cyg_mempool_var_try_alloc(cyg_handle_t varpool, cyg_uint32 size);

void cyg_mempool_var_free(cyg_handle_t varpool, void* p);

cyg_bool_t cyg_mempool_var_waiting(cyg_handle_t varpool);

void cyg_mempool_var_get_info(cyg_handle_t varpool, cyg_mempool_info* info);

Description

The variable size memory pool functions are used for allocating blocks of any size. Before memory can be allocated the pool must first be created by calling cyg_mempool_var_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. It also takes a pointer to a cyg_mempool_var 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_var_delete().

Memory can be allocated from the pool using a number of functions. They all take the paramtersvarpoolwhich indicates which pool should be used and the sizewhich indicates who big a memory area should be allocated. cyg_mempool_var_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_var_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_var_free().

Lastly it is possible to query information about the pool using the function cyg_mempool_var_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;