*** Help with Runtime Heap and Stack Tracking ***

Comments

2 comments

  • Avatar
    Mark Norton

    Look for malloc.c in the "C:\Program Files (x86)\Rowley Associates Limited\CrossWorks for ARM 3.3\source" or wherever yours is located.

     

    Here are a couple of functions I added for usefulness

     

    typedef struct heap_tag
    {
      struct heap_tag *next;
      unsigned size;
    } heap_t;
                                       
    extern heap_t __heap_start__;

    #define HEAP_CHUNK_SIZE  16   /* Must be a power of two. */

    uint32_t freemem(void) {         
      heap_t *p;
      uint32_t mem;

      __heap_lock();

      p = &__heap_start__;
      mem = 0;
      /* Search for best-fit block. */
      while (p) {
        mem += p->size;
        p = p->next;
      }
      __heap_unlock();
      return mem;
    }


    uint32_t largestblockmem(void) {         
      heap_t *p;
      uint32_t best_size;   

      __heap_lock();

      p = &__heap_start__;
      best_size = ~0U;
      while (p) {
        if (p->size > best_size) {
          best_size = p->size;
        }
        p = p->next;
      }
      __heap_unlock();
      return best_size;
    }

     

     

    0
    Comment actions Permalink
  • Avatar
    Mark Norton

    And BTW, I've been using Crossworks since 2006.  I love the tool and prefer it over any others.

    0
    Comment actions Permalink

Please sign in to leave a comment.