There are two sorts of memory pools. A variable size memory pool is for allocating blocks of any size. A fixed size memory pool, has the block size specified when the pool is created and only provides blocks of that size.
Blocking, non-blocking and "blocking with timeout" versions of these calls are provided.
void
cyg_mempool_var_create
(void *base, cyg_int32 size, cyg_handle_t *handle, cyg_mempool_var *var);Creates a variable size memory pool. The parameters are:
base of memory to use for pool
size of memory pool in bytes
returned handle of memory pool
space to put pool structure in
void
cyg_mempool_var_delete
(cyg_handle_t varpool);Deletes the variable size memory pool varpool.
void
*cyg_mempool_var_alloc
(cyg_handle_t
varpool, cyg_int32 size);Allocates a block of length size. This will block until the memory becomes available.
void
*cyg_mempool_var_timed_alloc
(cyg_handle_t varpool, cyg_int32 size, cyg_tick_count_t
abstime);Allocates a block of length size. If the requested amount of memory is not available, it will wait until abstime before giving up and returning NULL.
void
*cyg_mempool_var_try_alloc
(cyg_handle_t varpool, cyg_int32 size);Allocates a block of length size. NULL is returned if not enough is available.
void cyg_mempool_var_free
(cyg_handle_t
varpool, void *p);Frees memory back into variable size pool.
cyg_bool_t
cyg_mempool_var_waiting
(cyg_handle_t varpool);Returns true if any threads are waiting for memory in pool.
typedef struct { cyg_int32 totalmem; cyg_int32 freemem; void *base; cyg_int32 size; cyg_int32 blocksize; cyg_int32 maxfree; // The largest free block } cyg_mempool_info; |
void
cyg_mempool_var_get_info
(cyg_handle_t
varpool, cyg_mempool_info
*info);Puts information about a variable memory pool into the structure provided.
void
cyg_mempool_fix_create
(void *base, cyg_int32 size, cyg_int32 blocksize, cyg_handle_t *handle, cyg_mempool_fix *fix);Create a fixed size memory pool. This function takes the following parameters:
base of memory to use for pool
size of total spacerequested
size of individual elements
returned handle of memory pool
space to put pool structure in
void
cyg_mempool_fix_delete
(cyg_handle_t fixpool);Deletes the given fixed size memory pool.
void
*cyg_mempool_fix_alloc
(cyg_handle_t
fixpool);Allocates a block. If the memory is not available immediately, this blocks until the memory becomes available.
void
*cyg_mempool_fix_timed_alloc
(cyg_handle_t fixpool, cyg_tick_count_t abstime);Allocates a block. If the memory is not already available, it will try until abstime before giving up and returning a NULL.
void
*cyg_mempool_fix_try_alloc
(cyg_handle_t
fixpool);Allocates a block. NULL is returned if no memory is available.
void
cyg_mempool_fix_free
(cyg_handle_t fixpool, void *p);Frees memory back into fixed size pool.
cyg_bool_t
cyg_mempool_fix_waiting
(cyg_handle_t fixpool);Returns true if there are any threads waiting for memory in the given memory pool.
void
cyg_mempool_fix_get_info
(cyg_handle_t
fixpool, cyg_mempool_info *info);Puts information about a variable memory pool into the structure provided.