RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
RKH_MP_T Struct Reference

Defines the data structure used to memory block pool facility. More...

#include <rkhmp.h>

Data Fields

void * free
 The head of the linked list of free blocks. More...
 
RKH_MPNB_T nfree
 Number of free blocks remaining.
 
RKH_MPNB_T nblocks
 Total number of blocks in bytes. More...
 
RKH_MPBS_T bsize
 Maximum block size in bytes. More...
 
void * start
 The start of the original pool buffer. More...
 
void * end
 The last block in this pool.
 
RKH_MPNB_T nmin
 Minimum number of free blocks ever in this pool, i.e. holds the lowest number of free blocks ever present in the pool. More...
 
RKH_MPI_T mpi
 

Detailed Description

Defines the data structure used to memory block pool facility.

Since memory block pools consist of fixed-size blocks, there are never any fragmentation problems. Of course, fragmentation causes behavior that is inherently un-deterministic. In addition, the time required to allocate and free a fixed-size memory is comparable to that of simple linked-list manipulation. Lack of flexibility is the main drawback of fixed-size memory pools. The block size of a pool must be large enough to handle the worst case memory requirements of its users. Of course, memory may be wasted if many different size memory requests are made to the same pool. A possible solution is to make several different memory block pools that contain different sized memory blocks. Each memory block pool is a public resource.

The memory block pools contain a number of fixed-size blocks. The block size, in bytes, is specified during creation of the pool. Each memory block in the pool imposes a small amount of overhead the size of a C pointer. In addition, RKH may pad the block size in order to keep the beginning of each memory block on proper alignment.

The number of memory blocks in a pool depends on the block size and the total number of bytes in the memory area supplied during creation. To calculate the capacity of a pool (number of blocks that will be available), divide the block size (including padding and the pointer overhead bytes) into the total number of bytes in the supplied memory area.

The memory area for the block pool is specified during creation, and can be located anywhere in the target's address space. This is an important feature because of the considerable flexibility it gives the application.

Note
RKH prohibits an application from explicitly modifying the RKH_MP_T structure. The RKH's memory block pool structures can be located anywhere in memory, but it is most common to make it a global structure by defining it outside the scope of any function. An RKH memory pool is created when an memory pool is declared with the RKH_MP_T data type. The following listing declares "my_pool" memory pool:
RKH_MP_T my_pool;

Definition at line 189 of file rkhmp.h.

Field Documentation

void* free

The head of the linked list of free blocks.

The only data member strictly required for allocating and freeing blocks in the pool is the head of the free list 'free'.

Definition at line 198 of file rkhmp.h.

RKH_MPNB_T nblocks

Total number of blocks in bytes.

The type RKH_MPNB_T is configurable by the macro RKH_CFG_MP_SIZEOF_NBLOCK. The valid values [in bits] are 8, 16 or 32. Default is 8. The dynamic range of the RKH_MPNB_T data type determines the maximum number of blocks that can be stored in the pool.

Definition at line 216 of file rkhmp.h.

RKH_MPBS_T bsize

Maximum block size in bytes.

The type RKH_MPBS_T is configurable by the macro RKH_CFG_MP_SIZEOF_BSIZE. The valid values [in bits] are 8, 16 or 32. Default is 8. The dynamic range of the RKH_MPBS_T data type determines the maximum size of blocks that can be managed by the pool manager.

Definition at line 228 of file rkhmp.h.

void* start

The start of the original pool buffer.

The start and end pointers are used as delimiters of the valid range of memory blocks managed by this pool.

Definition at line 238 of file rkhmp.h.

RKH_MPNB_T nmin

Minimum number of free blocks ever in this pool, i.e. holds the lowest number of free blocks ever present in the pool.

The nmin low-watermark provides valuable empirical data for proper sizing of the memory pool.

Definition at line 255 of file rkhmp.h.

RKH_MPI_T mpi

Performance information. This member is optional, thus it could be eliminated in compile-time with RKH_CFG_MP_GET_INFO_EN.

Definition at line 265 of file rkhmp.h.


The documentation for this struct was generated from the following file: