Hi all,
I am developing a project using a Teensy 3.1; using a lot of dynamic memory allocations. With this in mind, I've written a small class that provides memory information simply. Using the initialize() and run() functions, the class monitors stack usage, simulates stack allocation and provides a low memory warning.
I'm wondering if this class would be of use to anyone else projects...
Cheers,
Adrian
Update: Now on SourceForge -
https://sourceforge.net/projects/teensy-3-x-rammonitor
class RamMonitor {
int32_t unallocated() const; // space between heap and stack (current): negitive if heap/stack crash
uint32_t stack_used() const; // stack size (current): grows into unallocated
uint32_t heap_total() const; // heap (dynamic mem) size: can grow into unallocated
uint32_t heap_used() const; // heap allocated
uint32_t heap_free() const; // free heap
int32_t free() const; // free ram: unallocated and unused heap
uint32_t total() const; // physical ram
// these functions (along with initialize and run)
// create the ellusion of stack allocation.
uint32_t stack_total() const; // stack size (historical)
int32_t stack_free() const; // calc stack usage before next stack growth
int32_t adj_unallocd() const; // space between heap and "alloc'd" stack: negitive if heap/stack crash
int32_t adj_free() const; // free ram: adjusted unallocated and unused heap
bool warning_lowmem() const; // returns true if stack and heap get close
bool warning_crash() const; // returns true if stack is in danger of overwriting heap
void initialize(); // initializes stack monitoring
void run(); // monitors stack and adjusted unallocated
};
I am developing a project using a Teensy 3.1; using a lot of dynamic memory allocations. With this in mind, I've written a small class that provides memory information simply. Using the initialize() and run() functions, the class monitors stack usage, simulates stack allocation and provides a low memory warning.
I'm wondering if this class would be of use to anyone else projects...
Cheers,
Adrian
Update: Now on SourceForge -
https://sourceforge.net/projects/teensy-3-x-rammonitor
class RamMonitor {
int32_t unallocated() const; // space between heap and stack (current): negitive if heap/stack crash
uint32_t stack_used() const; // stack size (current): grows into unallocated
uint32_t heap_total() const; // heap (dynamic mem) size: can grow into unallocated
uint32_t heap_used() const; // heap allocated
uint32_t heap_free() const; // free heap
int32_t free() const; // free ram: unallocated and unused heap
uint32_t total() const; // physical ram
// these functions (along with initialize and run)
// create the ellusion of stack allocation.
uint32_t stack_total() const; // stack size (historical)
int32_t stack_free() const; // calc stack usage before next stack growth
int32_t adj_unallocd() const; // space between heap and "alloc'd" stack: negitive if heap/stack crash
int32_t adj_free() const; // free ram: adjusted unallocated and unused heap
bool warning_lowmem() const; // returns true if stack and heap get close
bool warning_crash() const; // returns true if stack is in danger of overwriting heap
void initialize(); // initializes stack monitoring
void run(); // monitors stack and adjusted unallocated
};
Last edited: