Memory management


Detailed Description

The uSMARTX kernel implements a fixed size memory allocator with different heaps or memory pools. The allocating policy is first fit. Memory is always allocated from a pre-defined memory heap. Each memory heap has its own defined minimum allocatable size. In practice this is the size of a memory block. The allocated memory must alwasy be returned to the heap from which was allocated.


Defines

#define MEM_HEAP_CREATE(name, n, alloc_size)
 Create a memory heap.

Enumerations

enum  mb_size_t {
  MEM_MB_4_BYTE = (1 << 2), MEM_MB_8_BYTE = (1 << 3), MEM_MB_16_BYTE = (1 << 4), MEM_MB_32_BYTE = (1 << 5),
  MEM_MB_64_BYTE = (1 << 6), MEM_MB_128_BYTE = (1 << 7), MEM_MB_256_BYTE = (1 << 8), MEM_MB_512_BYTE = (1 << 9),
  MEM_MB_1024_BYTE = (1 << 10), MEM_MB_2048_BYTE = (1 << 11), MEM_MB_4096_BYTE = (1 << 12), MEM_MB_8192_BYTE = (1 << 13)
}

Functions

void * MEM_Alloc (HANDLE *ph, uint16 size)
 Allocate memory.
void MEM_Free (HANDLE *ph, void *pmem)
 Free memory.
STATUS MEM_IsHeapOwner (HANDLE *ph, void *pmem)
 Test parent of memory block.


Define Documentation

#define MEM_HEAP_CREATE name,
n,
alloc_size   ) 
 

Create a memory heap.

This macro creates and initilises a memory heap. The parameter alloc size should be of type mb_size_t.

Parameters:
name name of the memory heap
n number of memory blocks
alloc_size size of each memory block


Enumeration Type Documentation

enum mb_size_t
 

These defines define the valid memory block sizes.

Enumerator:
MEM_MB_4_BYTE  Memory block contains 4 bytes
MEM_MB_8_BYTE  Memory block contains 8 bytes
MEM_MB_16_BYTE  Memory block contains 16 bytes
MEM_MB_32_BYTE  Memory block contains 32 bytes
MEM_MB_64_BYTE  Memory block contains 64 bytes
MEM_MB_128_BYTE  Memory block contains 128 bytes
MEM_MB_256_BYTE  Memory block contains 256 bytes
MEM_MB_512_BYTE  Memory block contains 512 bytes
MEM_MB_1024_BYTE  Memory block contains 1024 bytes
MEM_MB_2048_BYTE  Memory block contains 2048 bytes
MEM_MB_4096_BYTE  Memory block contains 4096 bytes
MEM_MB_8192_BYTE  Memory block contains 8192 bytes


Function Documentation

void* MEM_Alloc HANDLE *  ph,
uint16  size
 

Allocate memory.

Allocate the required memory from the specified memory heap. The allocation is rounded to the memory block size.

Parameters:
ph handle to memory heap
size amount of memory to allocate
Return values:
pointer to allocated memory or null in there is no avaible memory
Todo:
Check what if the required number of memory blocks is 255

void MEM_Free HANDLE *  ph,
void *  pmem
 

Free memory.

Free the previously allocated memory by returning it to the specified memory pool.

Parameters:
ph handle to memory heap
pmem pointer to the previously allocated memory
Attention:
The memory must be returned to the pool from where was allocated

STATUS MEM_IsHeapOwner HANDLE *  ph,
void *  pmem
 

Test parent of memory block.

Test if the pointed memory belongs to a given memory heap.

Parameters:
ph handle to memory heap
pmem pointer to memory to test
Return values:
SYS_OK if the pointed memory belongs to the memory heap
SYS_EROR specified heap is not parent of the pointed memory


Generated on Sun Oct 16 22:23:55 2005 for uSmartX by  doxygen 1.4.3