## NAME

pool_create, pool_destroy, pool_alloc, pool_free - memory allocation

## SYNOPSIS

#include <sys.h>

int pool_create( int poolno,
  unsigned long startaddr , int length );
int pool_destroy( int poolno );
void *pool_alloc( int poolno , size_t size );
int pool_free( int poolno , void *buf );

pool_alloc() and pool_free() are callable from an ISR.

## DESCRIPTION

Memory pools are used to perform allocation of dynamic byte sized chunks of memory from specific memory regions. The pool calls to allocate and free memory, map onto the calls generally used at the application level - malloc() and free().

Microcontrollers and microprocessors often have memory ranges that provide different levels of performance. The combination of the use of the kalloc() and malloc() functions and their mappings onto the pool routines can ensure that certain high performance regions are used for high performance operations. For example, an internal fast memory region could be used for OS allocation (ie kalloc() ) and an external memory could be used for a graphics frame buffer.

Memory pools are used for dynamic allocation of variable size buffers. Up to 8 memory pools may be created. Valid poolno values are 0 through 7 inclusive.

A memory pool is created with a call to pool_create(). startaddr indicated the start address the pool area. length indicated the lenght of the pool area. It is up to the caller to provide a contiguous block of memory for the memory pool. poolno is a handle which will be used to access the pool. Memory pool poolno can be destroyed with a call to pool_destroy. pool_alloc returns a pointer to a dynamically allocated block of size bytes from memory pool poolno. pool_free returns the block of memory, allocated with a call to pool_alloc, to memory pool poolno.

## RETURN VALUES

pool_create() and pool_destroy() return 0 if sucessfull. If they fail, they set errno and return -1.

pool_alloc() returns 0 on failure and a pointer to the allocated buffer if successfull.

## ERRORS

pool_create() will set the following errors:

EINVAL
  poolno is not in the range 0 to 7 or is already in use.

pool_destroy() will set the following errors:

EINVAL
  poolno is not in the range 0 to 7 or has outstanding memory allocated.

## SEE ALSO

pt_create()

#### Home page (Kernel)

## < Copyright Rowebots Research Inc. and Multiprocessor Toolsmiths Inc. 1987-2018 >