Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Utility_AvailableMemory_blinky
Fork of AvailableMemory by
AvailableMemory.cpp
- Committer:
- segundo
- Date:
- 2010-11-07
- Revision:
- 0:a98bf0c96bf1
- Child:
- 11:0f5d5918761a
File content as of revision 0:a98bf0c96bf1:
#include "AvailableMemory.h"
#include <stdlib.h>
namespace segundo {
namespace Utilities {
int AvailableMemory() {
return AvailableMemory(256, 0x8000, true);
}
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
