Go Down

Topic: memory usage? problem with Sketch over 8200 bytes (Read 2492 times) previous topic - next topic

DarioCortese

Hi at all,

is there someone that know a system to measure, at runtime or compiler time, real avaiable memory.

I ask this because I have a problem when make a Sketch over 8KB (with Arduino UNO and IDE version 0022), after many tests I find that my upper static variable are located, into ram address 1858, and my dynamical variable (a byte inside my function, therefore located in the upper positions of the stack) have a ram address of 2275.
Do you remember that Stacks, tipically, work decrementing the ram location pointer from the upper of the avaiable memory (2303).
If I calculate difference 2275-1858 I have 417 free ram address before to have a collision of the stack with static variable, but in thi condition if I add a function (extend stack for call the function), or add two "int" inside an existing function, I have a abnormal response at runtime.

To comprove this phenomena, I have ottimizated the code remoning local variable inside variuos existing function, and with this optimization I have extended the Sketch code until 10KB without runtime problems.
At this point I have 420 bytes free, too; but now I need to add a small piece of code, calling a new function, and Now it appeare impossible.
Note that I have 20KB free of rom but in the reality it is impossible to use.

There is someone that can help me, please?
Thanks

AWOL

Don't forget that RAM and program memory are completely different.
Do you have large constant arrays or tables?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DarioCortese


Quote
Don't forget that RAM and program memory are completely different.
Do you have large constant arrays or tables?


No, I have only a small constant array (about 40bytes), but I have many constant string for debugging by serial.print.
How I saw before the problem appear to be the RAM, not the ROM (flash).

Oddly, the problem is appeared after that I wrote more than 8KB of flash program; I suppose than, after this flash size, the compiler manages in different mode the function calls, and this, for some reason that I don't understand, increases memory usage.


AWOL

Quote
but I have many constant string for debugging by serial.print.

The smoking gun.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DarioCortese

Quote
The smoking gun
.
Please, could you explain?

AWOL

I don't know how many print strings you've got (hint) but each one occupies RAM.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DarioCortese

Quote
I don't know how many print strings you've got (hint) but each one occupies RAM.

I thought that serial.print used the ROM and not RAM, but probably you are right, this would explain many things.

Now I try to write more short messages into serial.print.
thanks.

AWOL

Quote
I thought that serial.print used the ROM and not RAM, but probably you are right,

Serial.print uses char arrays.
That's all it knows about.
It can't know if they're in ROM or RAM, so just to be sure, it always puts them in RAM.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DarioCortese

It can't know if they're in ROM or RAM, so just to be sure, it always puts them in RAM.

AWOL you are right.
with this simple function...

DebugMessage(const char *str ){
   Serial.print(str);
   Serial.println((int)str, DEC);
}


I have traced the location of the constant string, and they are in low zone of the ram (from address 470 to 1860).

However, I don't understand how it is possible to have problems with some 400byte ram free, leaved from the higher static (1900) to the dynamic lower (2200).
Can someone explain?
Does anybody know which function, or system, use those ram locations (between 1900 and 2200)?


AWOL

Quote
Can someone explain?

Without seeing your code?
No, I seriously doubt it.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DarioCortese

thank AWOL,
Anyway thank you very much, your help was very helpful to me.
Now I'm shortening all the messages in order to save a ton of bytes

AWOL

You can put strings into PROGMEM, but you need to handle the printing yourself, but it is fairly simple.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Coding Badly

Now I'm shortening all the messages in order to save a ton of bytes


This will help...
http://arduiniana.org/libraries/flash/

DarioCortese


DarioCortese

Quote
You can put strings into PROGMEM, but you need to handle the printing yourself, but it is fairly simple.

Please can you post to me some examples, or some link?
Thanks

Go Up