News:

Let's find out together what makes a PIC Tick!

Main Menu

ERROR: Not enough RAM - message

Started by trastikata, Nov 13, 2021, 02:39 PM

Previous topic - Next topic

trastikata

Hi all,

Due to the shortage of chips nowadays I am trying to migrate some of the programs to different PICs. Some have less RAM and I have to optimize the code. Of course I get the familiar message:

"ERROR : Not enough RAM for all variables. Reduce the amount, or switch to a larger device."

By playing with variables and code I manage to compile the program and to estimate exactly how much RAM I fall short and how much further optimization and repurposing I need to do, however this is a tedious job editing back and forward the code just to see how much RAM I need.

So, my question is if there is a way to estimate how much is my program beyond the maximum RAM?

Les, I don't know if this is a lot of work or not, but if it is something really simple modifying the message to show the excess RAM requirements, that would be of help to other people too, I believe.

Thanks

diebobo

You could select a pic in yr program with more ram and then compile. You get a memory used info after successful compile. Then optimize until used ram is less then needed and switch back to the correct pic device.

top204

#2
The compiler cannot estimate the amount of RAM until it has compiled the code.

The compiler also uses, re-usable, system variables for its commands and expressions and boolean comparisons, so until the code has fully compiled, it does not know how much RAM the program uses.

There are some ways to use less RAM, but these depend on the program's code and the device type used. For example, alias variables that are re-used a lot, meaning they are classed as volatile types and do not store a value throughout the program's operation. Make sure any String variables or arrays are not larger than required etc...

Instead of using large expressions, seperate them into a few seperate temporary variables. This will ease the use of the compiler's expression stack variables. The same with expressions within comparisons and commands. Not a lot of variables are used by the compiler, but every little helps. :-)

My mantra when writing code in any language is "Think low level when writing high level", meaning write the code for efficiency. If only some other companies did this as they used too back in the 1980s and 1990s, Windows would be smaller and extremely fast, as would all other programs. :-)

trastikata

diebobo, this is excellent idea, thank you for the suggestion.

Les, thank you for taking the time to give the thorough explanation, all your advises are always well received.

joesaliba

Maybe if you have variables that are not used that often you could use eeprom?

John Drew

Trastikata,
When I wrote my moon tracking program some 15 years or so ago, I saved many bytes by separating complex maths expressions into multiple lines and temporary variables. Thanks to advice from Les at the time.
John