Function to calculate the memory available for malloc

Dependents:   AvailableMemory_HelloWorld MCBBThermostat helloaabbc SP14P1_skeleton

Embed: (wiki syntax)

« Back to documentation index

segundo::Utilities Namespace Reference

segundo::Utilities Namespace Reference

A collection of utilities. More...

Functions

int AvailableMemory (int resolution=256, int maximum=0x8000, bool disableInterrupts=true)
 Return the memory available for a malloc call.

Detailed Description

A collection of utilities.


Function Documentation

int AvailableMemory ( int  resolution = 256,
int  maximum = 0x8000,
bool  disableInterrupts = true 
)

Return the memory available for a malloc call.

This is done by a binary search approach calling malloc/free starting with a maximum.

Example:

 #include <stdio.h>
 #include "AvailableMemory.h"

 int main() {

     printf("Available memory (bytes to nearest 256) : %d\n", AvailableMemory());
     printf("Available memory (exact bytes) : %d\n", AvailableMemory(1));

 }
Parameters:
resolutionResolution in number of bytes, 1 will return the exact value, default will return the available memory to the nearest 256 bytes
maximumMaximum amount of memory to check, default is 32K (0x8000)
disableInterruptsDisable interrupts whilst checking, default is true
Returns:
Available memory in bytes accurate to within resolution

Definition at line 7 of file AvailableMemory.cpp.