Pages: [1]   Go Down
Author Topic: Arduino Memory Limit  (Read 505 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 119
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What happens when you go over the Arduino memory limit?  I'm trying to debug a problem where a value in my program sometimes goes back to 0.  Are there errors in the compilation stage, or does everything just go weird?

Thanks,
Zach
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Everything just goes weird.  You can't really determine exactly how much memory a program uses without running it.  But see: this function for getting an estimate of how much you're using.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been using this technique to see how much memory (heap) I have left.
Since the stack grows down and the heap up, the most common error I've experienced is (naturally) that these collide, which will result in really weird bugs.

Code:
uint8_t *ptr = (uint8_t *)malloc(4);
uint8_t *stackptr =  (uint8_t *)(SP);
printf_P(PSTR("heap ptr: %p\n"), ptr);
printf_P(PSTR("stackptr: %p\n"), stackptr);

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you're using the stack also to store return addresses, etc., then what you're describing is very much possible. On my Motorola 68HCS12 this is precisely what happens, and it mostly goes back to 0 only to reset and freeze.

If you're not using it to store return addresses, really they should just be overwriting each other -- which isn't good, but shouldn't cause it to crash. Of course, if you get to the point where you're starting to address negative memory locations, THEN you're going to have a problem (in all honesty, they should be treated unsigned if I remember correctly, so you'll just be accessing memory that's not really there).

EDIT: But I just realized that's not the OP smiley-cry

So, OP, what exactly are you doing that could cause you to run out of memory? That's quite a bit of processing to do on a RISC microcontroller.
« Last Edit: February 03, 2008, 01:13:28 pm by mpdelbuono » Logged

Pages: [1]   Go Up
Jump to: