Function to calculate the memory available for malloc

Dependents:   AvailableMemory_HelloWorld MCBBThermostat helloaabbc SP14P1_skeleton

Committer:
segundo
Date:
Mon Nov 08 13:21:36 2010 +0000
Revision:
15:d00289c15c89
Parent:
14:5d5fc6b4ed16

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
segundo 10:7474d5df69c2 1 /** @file
segundo 12:3004855925ff 2 * Return the memory available for a malloc call.
segundo 3:9092256004a5 3 */
segundo 0:a98bf0c96bf1 4 #ifndef SEGUNDO_UTILITIES_AVAILABLEMEMORY_H
segundo 0:a98bf0c96bf1 5 #define SEGUNDO_UTILITIES_AVAILABLEMEMORY_H
segundo 6:e94f3a11bad7 6
segundo 9:caba868a4c1a 7 /**
segundo 9:caba868a4c1a 8 * Segundo Equipo
segundo 9:caba868a4c1a 9 */
segundo 0:a98bf0c96bf1 10 namespace segundo {
segundo 9:caba868a4c1a 11 /**
segundo 9:caba868a4c1a 12 * A collection of utilities
segundo 14:5d5fc6b4ed16 13 */
segundo 14:5d5fc6b4ed16 14 namespace Utilities {
segundo 14:5d5fc6b4ed16 15
segundo 15:d00289c15c89 16 /** Return the memory available for a malloc call.
segundo 15:d00289c15c89 17 * This is done by a binary search approach
segundo 15:d00289c15c89 18 * calling malloc/free starting with a maximum.
segundo 13:c8a20f79e011 19 *
segundo 13:c8a20f79e011 20 * Example:
segundo 13:c8a20f79e011 21 * @code
segundo 13:c8a20f79e011 22 * #include <stdio.h>
segundo 13:c8a20f79e011 23 * #include "AvailableMemory.h"
segundo 13:c8a20f79e011 24 *
segundo 13:c8a20f79e011 25 * int main() {
segundo 13:c8a20f79e011 26 *
segundo 13:c8a20f79e011 27 * printf("Available memory (bytes to nearest 256) : %d\n", AvailableMemory());
segundo 13:c8a20f79e011 28 * printf("Available memory (exact bytes) : %d\n", AvailableMemory(1));
segundo 13:c8a20f79e011 29 *
segundo 13:c8a20f79e011 30 * }
segundo 15:d00289c15c89 31 * @endcode
segundo 15:d00289c15c89 32 * @param resolution Resolution in number of bytes,
segundo 11:0f5d5918761a 33 * 1 will return the exact value,
segundo 12:3004855925ff 34 * default will return the available memory to the nearest 256 bytes
segundo 12:3004855925ff 35 * @param maximum Maximum amount of memory to check, default is 32K (0x8000)
segundo 11:0f5d5918761a 36 * @param disableInterrupts Disable interrupts whilst checking, default is true
segundo 11:0f5d5918761a 37 * @return Available memory in bytes accurate to within resolution
segundo 1:d8432d8a5b6d 38 */
segundo 11:0f5d5918761a 39 int AvailableMemory(int resolution = 256, int maximum = 0x8000, bool disableInterrupts = true);
segundo 0:a98bf0c96bf1 40
segundo 0:a98bf0c96bf1 41 } // namespace Utilities
segundo 0:a98bf0c96bf1 42 } // namespace segundo
segundo 0:a98bf0c96bf1 43
segundo 0:a98bf0c96bf1 44 using namespace segundo::Utilities;
segundo 0:a98bf0c96bf1 45
segundo 0:a98bf0c96bf1 46 #endif // SEGUNDO_UTILITIES_AVAILABLEMEMORY_H