# Utilities
[RTOS]

General utilities provided by the RTOS. More...

## Functions
void * | Malloc (int size)
| Dynamically allocate memory from the heap.
void * | MallocWait (int size, int interval)
| Same as Malloc, but keeps trying until it succeeds.
void | Free (void *memory)
| Free memory from the heap.

## Detailed Description

General utilities provided by the RTOS.

FreeRTOS has several options for memory management - we've chosen a default one here which is pretty sensible in most cases, but you're of course welcome to use whatever makes most sense for your application. See http://www.freertos.org/a00111.html for the available options.

## Function Documentation

void Free | ( | void * | memory | ) |

Free memory from the heap.

Once you've allocated memory using Malloc(), free it when you're done with it. It's usually a good idea to set the pointer the freed memory to NULL after you've freed it.

Parameters:

  | memory | A pointer to the memory created by Malloc( )

See also:
  Malloc(), System_GetFreeMemory( )

Example

        char *bufferPtr = Malloc( 1024 ); // allocate 1024 bytes of memory
        // ...your processing here...
        Free( bufferPtr ); // then free the memory when you're done with it

Definition at line 523 of file rtos.c.

void* Malloc | ( | int | size | ) |

Dynamically allocate memory from the heap.

This is pretty much the same as a normal malloc(), but for the SAM7X.

Returns:
  A pointer to the allocated memory, or NULL if the memory was not available.

See also:
  Free(), System_GetFreeMemory( )

Example

        int bufferSize = 1024;
        char *bufferPtr = Malloc( bufferSize );
        // now you have a 1024 character buffer

Definition at line 472 of file rtos.c.

void* MallocWait | ( | int | size,
|  | int | interval |
| ) |  |  |

Same as Malloc, but keeps trying until it succeeds.

This is a convenience function that will continue to call Malloc( ) at a given interval until it returns successfully. Once this function returns, you know you have been allocated the memory you asked for.

Parameters:

  | size | An integer specifying the amount of memory, in bytes, you want to allocate.
  | interval | An integer specifying the number of milliseconds to wait between successive attempts to allocate memory. It's best to not set this too low, as it will be a bit taxing on the system.

Returns:
  A pointer to the allocated memory, or NULL if the memory was not available.

See also:
  Free(), System_GetFreeMemory( )

Example

        char *bufferPtr = MallocWait( 1024, 100 );
        // now you have a 1024 character buffer

Definition at line 495 of file rtos.c.