program to test a possible memory leak when using NTP
Dependencies: NetServices mbed
AvailableMemory.h@2:006625ab89d2, 2011-03-06 (annotated)
- Committer:
- hlipka
- Date:
- Sun Mar 06 21:28:42 2011 +0000
- Revision:
- 2:006625ab89d2
- Parent:
- 0:3986c9f76b09
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hlipka | 0:3986c9f76b09 | 1 | /** @file |
hlipka | 0:3986c9f76b09 | 2 | * Return the memory available for a malloc call. |
hlipka | 0:3986c9f76b09 | 3 | */ |
hlipka | 0:3986c9f76b09 | 4 | #ifndef SEGUNDO_UTILITIES_AVAILABLEMEMORY_H |
hlipka | 0:3986c9f76b09 | 5 | #define SEGUNDO_UTILITIES_AVAILABLEMEMORY_H |
hlipka | 0:3986c9f76b09 | 6 | |
hlipka | 0:3986c9f76b09 | 7 | /** |
hlipka | 0:3986c9f76b09 | 8 | * Segundo Equipo |
hlipka | 0:3986c9f76b09 | 9 | */ |
hlipka | 0:3986c9f76b09 | 10 | namespace segundo { |
hlipka | 0:3986c9f76b09 | 11 | /** |
hlipka | 0:3986c9f76b09 | 12 | * A collection of utilities |
hlipka | 0:3986c9f76b09 | 13 | */ |
hlipka | 0:3986c9f76b09 | 14 | namespace Utilities { |
hlipka | 0:3986c9f76b09 | 15 | |
hlipka | 0:3986c9f76b09 | 16 | /** Return the memory available for a malloc call. |
hlipka | 0:3986c9f76b09 | 17 | * This is done by a binary search approach |
hlipka | 0:3986c9f76b09 | 18 | * calling malloc/free starting with a maximum. |
hlipka | 0:3986c9f76b09 | 19 | * |
hlipka | 0:3986c9f76b09 | 20 | * Example: |
hlipka | 0:3986c9f76b09 | 21 | * @code |
hlipka | 0:3986c9f76b09 | 22 | * #include <stdio.h> |
hlipka | 0:3986c9f76b09 | 23 | * #include "AvailableMemory.h" |
hlipka | 0:3986c9f76b09 | 24 | * |
hlipka | 0:3986c9f76b09 | 25 | * int main() { |
hlipka | 0:3986c9f76b09 | 26 | * |
hlipka | 0:3986c9f76b09 | 27 | * printf("Available memory (bytes to nearest 256) : %d\n", AvailableMemory()); |
hlipka | 0:3986c9f76b09 | 28 | * printf("Available memory (exact bytes) : %d\n", AvailableMemory(1)); |
hlipka | 0:3986c9f76b09 | 29 | * |
hlipka | 0:3986c9f76b09 | 30 | * } |
hlipka | 0:3986c9f76b09 | 31 | * @endcode |
hlipka | 0:3986c9f76b09 | 32 | * @param resolution Resolution in number of bytes, |
hlipka | 0:3986c9f76b09 | 33 | * 1 will return the exact value, |
hlipka | 0:3986c9f76b09 | 34 | * default will return the available memory to the nearest 256 bytes |
hlipka | 0:3986c9f76b09 | 35 | * @param maximum Maximum amount of memory to check, default is 32K (0x8000) |
hlipka | 0:3986c9f76b09 | 36 | * @param disableInterrupts Disable interrupts whilst checking, default is true |
hlipka | 0:3986c9f76b09 | 37 | * @return Available memory in bytes accurate to within resolution |
hlipka | 0:3986c9f76b09 | 38 | */ |
hlipka | 0:3986c9f76b09 | 39 | int AvailableMemory(int resolution = 256, int maximum = 0x8000, bool disableInterrupts = true); |
hlipka | 0:3986c9f76b09 | 40 | |
hlipka | 0:3986c9f76b09 | 41 | } // namespace Utilities |
hlipka | 0:3986c9f76b09 | 42 | } // namespace segundo |
hlipka | 0:3986c9f76b09 | 43 | |
hlipka | 0:3986c9f76b09 | 44 | using namespace segundo::Utilities; |
hlipka | 0:3986c9f76b09 | 45 | |
hlipka | 0:3986c9f76b09 | 46 | #endif // SEGUNDO_UTILITIES_AVAILABLEMEMORY_H |