Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

XgHeap


Functions

void * NutHeapAlloc (u_short size)
 Allocate a block from heap memory.

void * NutHeapAllocClear (u_short size)
 Allocate an initialized block from heap memory.

int NutHeapFree (void *block)
 Return a block to heap memory.

void NutHeapAdd (void *addr, u_short size)
 Add a new memory region to the free heap.

u_short NutHeapAvailable (void)
 Return the number of bytes available.


Variables

HEAPNODE *volatile heapFreeList = 0
 List of free nodes.

u_short available = 0
 Number of bytes available.


Function Documentation

void NutHeapAdd void *    addr,
u_short    size
 

Add a new memory region to the free heap.

This function is automatically called by Nut/OS during initialization.

Applications typically do not call this function.

Parameters:
addr  Start address of the memory region.
size  Number of bytes of the memory region.

void* NutHeapAlloc u_short    size
 

Allocate a block from heap memory.

This functions allocates a memory block of the specified size and returns a pointer to that block.

The actual size of the allocated block is larger than the requested size because of space required for maintenance information. This additional information is invisible to the application.

The routine looks for the smallest block that will meet the required size and releases it to the caller. If the block being requested is usefully smaller than the smallest free block then the block from which the request is being met is split in two. The unused portion is put back into the free-list.

The contents of the allocated block is unspecified. To allocate a block with all bytes set to zero use NutHeapAllocClear().

Note:
Do not use this function in interrupt routines.
Parameters:
size  Size of the requested memory block.
Returns:
Pointer to the allocated memory block if the function is successful or NULL if the requested amount of memory is not available.
Examples:
adds/app/flash.

void* NutHeapAllocClear u_short    size
 

Allocate an initialized block from heap memory.

This functions allocates a memory block of the specified size with all bytes initialized to zero and returns a pointer to that block.

Parameters:
size  Size of the requested memory block.
Returns:
Pointer to the allocated memory block if the function is successful or NULL if the requested amount of memory is not available.

u_short NutHeapAvailable void   
 

Return the number of bytes available.

Returns:
Number of bytes.

int NutHeapFree void *    block
 

Return a block to heap memory.

An application calls this function, when a previously allocated memory block is no longer needed.

The heap manager checks, if the released block adjoins any other free regions. If it does, then the adjacent free regions are joined together to form one larger region.

Note:
Do not use this function in interrupt routines.
Parameters:
block  Points to a memory block previously allocated through a call to NutHeapAlloc().
Returns:
0 on success, -1 if the caller tried to free a block which had been previously released.


Generated on Thu Jan 30 22:30:59 2003 for EduNet by doxygen1.2.18