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

Memory saving techniques

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



Joined: 14 Mar 2006
Posts: 2

View user's profile Send private message

Memory saving techniques
PostPosted: Tue Mar 14, 2006 11:26 pm     Reply with quote

I'm currently attempting to devleop a bootloader/debugger utility for the PIC16F877A. In the process though, I've found that I seem to be using up a lot of RAM (my code uses up about 25% of the total available ROM space). I always get "Not enough RAM for all variables" errors when I compile. I know I am not using even 100 bytes of memory at once with all my local variables and can verify this by drawing out my call tree.

A peek into the symbol file shows that some of my functions are asking for too much scratch space (although it doesn't show how local variables are being allocated, possibly because it complains of not enough RAM). I've managed to cut this list down to only a few functions using the following techniques:

  • Using putc() instead of printf() for short strings
  • Splitting up math functions onto several lines. Such as:
    var1 = var2+(var3 & var4);
    into
    var1= var3 & var4;
    var1+= var2;
  • Eliminating unnecessary local variables and sizing arrays to absolute minimum values.

Would using pointers for variables larger than 8-bits help to reduce memory usage?
These functions don't call on other functions save to convert an ASCII string to an integer or to perform some operations on system registers which don't require any local variables. Would implementing code inline and avoiding a function call help if no local variables are needed in said function call?
I'm also not really sure how I can reduce a switch statment I use to decide what to do based on user menu choices.

I'm wondering if anyone else has any memory saving hints or tips and/or answers to my questions.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 14, 2006 11:45 pm     Reply with quote

Quote:

I always get "Not enough RAM for all variables" errors when I compile.
I know I am not using even 100 bytes of memory at once with all my
local variables and can verify this by drawing out my call tree.


Have you enabled the use of all RAM ? To do so, add the line
shown below.
Code:

#include <16F877A.H>
#device *=16     <--  Add this line to enable all RAM
ScottJ



Joined: 14 Mar 2006
Posts: 2

View user's profile Send private message

PostPosted: Wed Mar 15, 2006 7:25 pm     Reply with quote

Thanks, that seems to fix my memory woes!
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