Pages: [1]   Go Down
Author Topic: Memory creep any suggestions?  (Read 525 times)
0 Members and 1 Guest are viewing this topic.
Gloucester
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know my listing is a mess but it is work in progress.
It is yet another weather monitor with a simple web printout of current status, with averaging function on all readings,  saved to SD card with time stamp.

I seem to be suffering memory creep thus my program and data is crashing into each other. how can I reduce the overheads? I noticed that Long's and floats use 4 bytes each. I could use strings more but not sure if this would save much? (or even how!)
Yours Simon M.

* Hum_Temp_Baro_Ave_SD_Web_notLCD_Time.pde (18.84 KB - downloaded 8 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 637
Posts: 34594
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I seem to be suffering memory creep thus my program and data is crashing into each other.
What ever else is happening this is not. This is because the processor has Harvard architecture where data space and program space are separate.
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 936
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As mike said, you are not colliding data and code, however you could be running out of memory or getting fragmented to the point where it fails.  Using Strings extensively can lead to that sometimes.  To test for out of memory conditions just include:

#include <MemoryFree.h>

and then print it so you can check what's going on.

Serial.println(freeMemory());

You can sprinkle these prints around to see what code does what and so forth. 

You need about 200 bytes free to allow for subroutine calls, temporary variables and such so check accordingly.
Logged

Trying to keep my house under control http://www.desert-home.com/

Gloucester
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have used the #include <MemoryFree.h> 'utility' and indeed when I go below 240 ish it dies. Why does is number go down over time? is the SP overflowing? I do expect the amount to drop through the program execution, but I can't understand why on each loop it gets less & less?  I do use arrays for averaging but these are reused on each full loop through. I might resort to storing raw data and calculate the other stuff when called.
Will clearing the arrays save memory, or will filling the arrays at boot to their max stop fragmentation?

Yours Simon M.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4816
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Having variable(s) go out of scope should free them but for the next use is whether or not there is a big enough continuous space to allocate for the next new need.

I'm new to this but it appears that println() assembles the string to be printed in RAM. Does that de-allocate when the string is printed? Oh no, it's worse than I thought:
Quote
(Note: string literals take up room in the Flash (program) memory AND the RAM. When the program starts, the strings are copied from Flash to RAM.)
To say the least, there is room for improvement. Hmmm, it's already been seen to:
Quote
Third, if you have a lot of strings that you absolutely need, or large arrays of data that do not change, then use the PROGMEM directive. This is a way of telling the Arduino to put data into Flash (program) memory only, without copying it into RAM. This technique is useful if you have a lot of data that does not change, and still have Flash (program) memory available.

The quotes are from an excellent article by Gian Pablo, Making the most of Arduino memory:
http://itp.nyu.edu/~gpv206/2008/04/making_the_most_of_arduino_mem.html

Long ago I remember when VM was taught as used to make 1k of RAM seem like 16k. Don't laugh (so okay I did!), that was back in the day when the dinosaurs ruled and school texts still taught decade-old techniques.
Perhaps a VM library to be used alongside the SD library?
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26528
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Without a memory fault exception, implementing VM is going to be tricky.
Logged

"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.

Italy
Offline Offline
Full Member
***
Karma: 0
Posts: 127
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I seem to be suffering memory creep

Do you mean you consume a bit more memory after ever loop?

If so one way to find out what is happening is to simplify your program bit by bit. For example take out averageing() and see if THAT gives you memory creep problems. Then take out webServer() and see if THAT gives you problems.

Do this on a copy of your program so that when you find the culprit you can correct it in your original.

It may be neither, but it would be good to eliminate them.




Logged

Owen F. Ransen

Pages: [1]   Go Up
Jump to: