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