Go Down

Topic: Programatically accessing stack and heap pointers? (Read 221 times) previous topic - next topic

random_vamp

With a set of libraries I've been working on I ran into some issues which appeared to be caused by memory corruption, and upon further investigation (mainly various forums and http://www.nongnu.org/avr-libc/user-manual/malloc.html) and printing out variable addresses I suspect this was caused by the heap and stack colliding.

I'm looking to go through my libraries to minimize the memory usage there, however I'm not finding any good pointers to tools for analyzing the memory utilization (I see some posts regarding avr-size utility on Linux but I need something for MacOS).  The simplest way I can think of would be to directly point out the stack and heap pointers at various points and perhaps add some #def'd instrumentation to track utilization.  However I'm not finding a means of accessing the stack or heap pointers, are these accessible from a arduino program?

joshuabardwell

This may be what you're looking for.

Code: [Select]
int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

JimEli

http://playground.arduino.cc/Code/AvailableMemory

Nick Gammon


(I see some posts regarding avr-size utility on Linux but I need something for MacOS). 


I use a Mac and have avr-size:

Code: [Select]

/usr/local/CrossPack-AVR/bin/avr-size


Not quite sure where I got it though.

However since all the other things (like avr-gcc) work on a Mac, it isn't that surprising.

Not that I think it will help in this case.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

random_vamp


Code: [Select]
int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}



Yeah, this is probably exactly what I was looking for.  Thanks!

Go Up