Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:39 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Memory Issues

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 12:51pm 04 Oct 2012
Copy link to clipboard 
Print this post

Recently I found some software I wrote for QB45 on an IBM XT and thought it may be a good project to convert it to run on the Maximite. I have come across a stumbling block and hope the wealth of knowledge attached to this forum may be able to help me. The main issue is "Error: not enough memory"

Here are the statistics:
MEMORY
48kB (58%) Program (1283 lines)
29kB (34%) 18 Variables
2kB ( 3%) General
4kB ( 5%) Free

Like the early Basics, is there a memory saving in placing multiple lines in one line?
Is there a simple way we can we use the abundance of memory on the SD Card?
Are there any other tricks to maximise the use of available memory? (Sorry about the pun)

Looking forward to your suggestions.
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5078
Posted: 01:38pm 04 Oct 2012
Copy link to clipboard 
Print this post

Are there any data statements within the program that could be saved as text files on the SD card? One trick I used was storing chunks of data in different text files, and then reading in the text file when and only when you need that data. Remember reading from a SD card is fast, its writing thats slow and wears the card out.

Also you can reuse variables, and clear them after use.

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 05:53pm 04 Oct 2012
Copy link to clipboard 
Print this post

Each line consumes two extra bytes of memory compared to using the colon to separate commands - so you do not save much by joining lines. You could load and run programs on the fly using the RUN command but that is very messy to use and requires you to save session data to the SD card.

Probably the best memory saver is to strip out all comments and shorten literal strings.

Geoff

General note: Please understand if I go silent for the next month (I have rented an apartment in Rome and it has no Internet - which is probably a good thing).
Geoff Graham - http://geoffg.net
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2914
Posted: 06:25pm 04 Oct 2012
Copy link to clipboard 
Print this post

  Geoffg said  
General note: Please understand if I go silent for the next month (I have rented an apartment in Rome and it has no Internet - which is probably a good thing).


A well earned break Geoff,

Enjoy the peace and quiet (If I could only remember that quote from `The Castle' but I am sure it will be quoted here before you check your bags).

Have a great time and I am sure that all of the TBS's, as do I, wish you an enjoyable break.

Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 09:28pm 04 Oct 2012
Copy link to clipboard 
Print this post

Gizmo, I read & save all initial and end variables to a data file on the SD card and I dont have any data stements in the program.

Geoff, I will strip out all the comments and see how much extra memory I can gain. I am very envious of your forthcoming vacation, have a great time and look forward to your work in the future.
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 05:02pm 07 Oct 2012
Copy link to clipboard 
Print this post

I have stripped out all comments and indents, abbreviated where possible and have the following stats:
MEMORY
39kB (47%) Program (1115 lines)
29kB (35%) 18 Variables
2kB ( 3%) General
14kB (15%) Free

Now the program tries to run but I still don't have enough memory to run the editor.

Is there any other way of editing (no line numbers) without having to do it on the PC and reloading the program each time?
 
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 05:07pm 07 Oct 2012
Copy link to clipboard 
Print this post

  Graeme Meager said   I have stripped out all comments and indents, abbreviated where possible and have the following stats:
MEMORY
39kB (47%) Program (1115 lines)
29kB (35%) 18 Variables
2kB ( 3%) General
14kB (15%) Free

Now the program tries to run but I still don't have enough memory to run the editor.

Is there any other way of editing (no line numbers) without having to do it on the PC and reloading the program each time?
Which version of MMbasic and configuration of the Maximite are you using?
You can edit the program directly without line numbers on the Maximite hardware with version 3.1 or later.Edited by djuqa 2012-10-09
VK4MU MicroController Units

 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 11:18pm 07 Oct 2012
Copy link to clipboard 
Print this post

Djuqa,
Version 3.1 only permits 30KB for program memory and it seems the program I wish to convert is around 40KB. I am using MMBasic version 4.0 and have tried CGMMSTICK1 as well as Duinomite. My original intention was to make use of one of these units with this project but as I said in an earlier post they don't have enough room to run the editor. I can run the editor on the Maximite (not sure why when it says it has only 9KB free and the other units have 14KB) so it looks like I will have to do the coding and testing on the Maximite.
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 11:31pm 07 Oct 2012
Copy link to clipboard 
Print this post

If you run version 3.2C you should get enough memory. If I recall correctly, it had a shared memory pool which should allow enough for your program.
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 11:55pm 07 Oct 2012
Copy link to clipboard 
Print this post

BobD,
Please correct me if I am misled but the issue may not be the MMbasic version but the fact that I only have around 84KB of total memory available after the Basic is loaded. In this instance the program, variables and general memory use up 77KB. I have been looking for ways of economising on the use of this memory.
 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 12:09am 08 Oct 2012
Copy link to clipboard 
Print this post

Just a question, is that right, 18 variables requiring 27 kbytes memory ?
That is over a kbyte per variable ?

cheers
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 12:19am 08 Oct 2012
Copy link to clipboard 
Print this post

chronic,
That is right, all the variables declared are arrays and half of them are string arrays. I think the string arrays are very memory hungry.
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 11:33am 08 Oct 2012
Copy link to clipboard 
Print this post

Yep, strings and their arrays are memory hungry.

Try commenting out the line where you define each of the string arrays and check the resulting memory usage, then replace some of the big memory hogs with files on the SD card.

You could also work out the biggest memory memory hogs with a calculator because strings are all fixed length (if I recall correctly), so the arrays with the biggest number of entries will be the first candidates for replacement.

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 12:11pm 08 Oct 2012
Copy link to clipboard 
Print this post

Strings are a fixed 256 bytes.

memory
dim test$(128)
memory


If your strings are short, can you combine them for storage?
Four 64 byte strings (63 with an end character) would be a big saving.

Jim

VK7JH
MMedit   MMBasic Help
 
mattma
Newbie

Joined: 01/10/2012
Location: Australia
Posts: 25
Posted: 12:26pm 08 Oct 2012
Copy link to clipboard 
Print this post

I ran into the same problem at 1280 lines of code too. it must be a magic number.

I was wondering if any of the MM source code hackers here think it might be possible to use the A: drive space for program storage? With the SD card available it seems that we could live without the A: drive for file storage. Maybe it could be used to store libraries of functions that are 'called'/loaded when then are called and this would leave the main program memory for memory only.

Does anyone know if this is possible? Anyone know how to do it?

Cheers
Matt
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 02:41pm 08 Oct 2012
Copy link to clipboard 
Print this post

You might be able to make use of the RUN command.
The first program has the menu and it can then RUN different programs to do their own thing, returning to the main menu using the RUN command.

Or: the first program collects the data and the second one runs the analysis.

This is the sort of thing I had to resort to in the 'good old days' of Microbee and ZX81.

Be careful with the A drive, the flash memory has a limited number of read/write cycles and accessing the A drive might cause the display to flash.

Jim
VK7JH
MMedit   MMBasic Help
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 07:13pm 08 Oct 2012
Copy link to clipboard 
Print this post

Another feature you may be able to use is to define an array just before you need to use it and "Erase" it when you have finished with it. Erasing it frees up the memory it occupied.
Cheers,
Hugh
 
aargee
Senior Member

Joined: 21/08/2008
Location: Australia
Posts: 255
Posted: 03:04pm 09 Oct 2012
Copy link to clipboard 
Print this post

  Geoffg said   Each line consumes two extra bytes of memory compared to using the colon to separate commands - so you do not save much by joining lines. You could load and run programs on the fly using the RUN command but that is very messy to use and requires you to save session data to the SD card.

Probably the best memory saver is to strip out all comments and shorten literal strings.

Geoff

General note: Please understand if I go silent for the next month (I have rented an apartment in Rome and it has no Internet - which is probably a good thing).


Ahh, a much more pleasant time to visit Rome than when we were there (early July) - enjoy yourself and the exchange rate!

- Rob.


For crying out loud, all I wanted to do was flash this blasted LED.
 
mattma
Newbie

Joined: 01/10/2012
Location: Australia
Posts: 25
Posted: 12:42pm 12 Oct 2012
Copy link to clipboard 
Print this post

Is it possible to add more memory to the PIC32?
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024