finds size of largest block of heap memory
Dependents: myBlueUSB mbed_TANK_Kinect myBlueUSB_ros myBlueUSB_localfix
Diff: AvailableMemory.cpp
- Revision:
- 0:2b2aa11cebd7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AvailableMemory.cpp Wed May 04 09:14:02 2011 +0000 @@ -0,0 +1,34 @@ +#include "AvailableMemory.h" +#include <stdlib.h> + +namespace segundo { +namespace Utilities { + +int AvailableMemory(int resolution, int maximum, bool disableInterrupts) { + + if (resolution < 1) resolution = 1; + if (maximum < 0) maximum = 0; + + int low = 0; + int high = maximum + 1; + + if (disableInterrupts) __disable_irq(); + + while (high - low > resolution) { + int mid = (low + high) / 2; + void* p = malloc(mid); + if (p == NULL) { + high = mid; + } else { + free(p); + low = mid; + } + } + + if (disableInterrupts) __enable_irq(); + + return low; +} + +} // namespace Utilities +} // namespace segundo \ No newline at end of file