CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Odd Memory Usage

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
object01



Joined: 13 May 2004
Posts: 90
Location: Nashville, TN

View user's profile Send private message Send e-mail Visit poster's website

Odd Memory Usage
PostPosted: Thu Jun 03, 2004 8:11 am     Reply with quote

I'm very new to embedded software, and I'm hoping someone can help me understand why I'm observing this:

I'm working with a PIC16F88, and up until recently I've been getting lots of "Not enough RAM for all variables" errors. As a pure shot-in-the-dark, I commented out a 'char buffer[59]' declaration at global scope, and commented out all references to it. All of a sudden, my code compiles and I have 59% RAM free! Put the buffer back, and I'm back to "not enough RAM." (PCM 3.189) How is this possible?
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Jun 03, 2004 9:23 am     Reply with quote

There is not an exact 1:1 relationship between the number of bytes you allocate in your code and the number of bytes the compiler uses. Your array of 59 characters is about 16% of total available RAM. If the functions where you were using the array require accessor variables or scratchpad then the size goes up. Also in some cases the compiler use the RETLW method of accessing RAM arrays and that can take more space too.

If your functions use argument lists there will be scratchpad RAM required for passing arguments.

If the compiler can't resolve the scope of a variable it may not reuse that RAM eventhough it could have.

Another thing that seems to eat up RAM is the way the compiler assigns things to banks. It never quite gets things fit perfectly so you loose a few bytes here and there. You can override the automatic assignment of variables by doing it yourself.

Lots of interactions cause the memory used or available to be off.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 03, 2004 9:53 am     Reply with quote

Quote:
All of a sudden, my code compiles and I have 59% RAM free!
Put the buffer back, and I'm back to "not enough RAM."
(PCM 3.189) How is this possible?


It's possible because the default mode for the CCS compiler
is to not use ram above address 0xFF, for the 16-series PICs.

To enable usage of this RAM, you need to add the #device *=16
directive. When you do this, the compiler will use more ROM,
due to the code used for bank switching, but it will get rid of
your problems with "out of RAM" errors.

Example:
Code:
#include <16F88.H>
#device *=16

Put the "device" statement on the next line after the main include
statement, exactly as shown above. That's important.
prwatCCS



Joined: 10 Dec 2003
Posts: 67
Location: West Sussex, UK

View user's profile Send private message

PostPosted: Fri Jun 04, 2004 3:46 am     Reply with quote

I have found it sometime helps to place large arrays at the beginning of the next bank of ram, rather than let the compiler try and fit it (and fail).
_________________
Peter Willis
Development Director
Howard Eaton Lighting Ltd UK
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group