Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 25 of 32

Thread: Memory Status and Monitoring

Threaded View

  1. #1

    Memory Status and Monitoring

    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
    };
    Last edited by cyborgv2; 02-19-2016 at 01:43 PM. Reason: Source Published

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •