Thursday, July 14, 2005

Running out of RAM

Out of RAM, of all things. But it can happen.

At my work, we use (among others) ATMEL ATMega128 micorcontrollers. As I increased the size of two buffers to 256 bytes, the box started screwing up badly, in completely unpredictable ways. Most of the time, it would not even finish booting.

After a great lot of head scratching, then cursing, then making obscene gestures at my monitor (I do that a lot), I finally discovered the reason: The buffers I had allocated had run into the stack (or rather, the stack had run into them), and since they were constantly changing, the return addresses on the stack, where the runtime system expected them, were worth fuck all after a few milliseconds.

The thing has only four K of RAM, for crying out loud. I have never before had to code for such a resource - deprived environment. It's certainly very instructive. But it can also be annoying as hell. You never know how far exactly you can go, since the size of the stack, after all, depends on the the nesting of your function calls. I hate that feeling, when you never can be completely sure some situation with deeply nested calls doesn't come along and mess everything up.

I've had that feeling before when coding.

I suspect there's actually something that can be done about this. Since we don't use dynamic memory allocation, we should be able to figure out the maximum safe stack size.

Maybe that feeling is actually an indication of a deficiency in our process.
Maybe it can be fixed.
Maybe it needs to.

1 Comments:

Anonymous Anonymous said...

Stack overflows really do suck :/
I'm just debugging one and I'm starting to like the idea of making gestures to my pc too. At the moment I'm still at the cursing-stage :D

1:41 AM  

Post a Comment

<< Home