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

RAM used - worst case

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



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

RAM used - worst case
PostPosted: Wed Sep 05, 2007 1:42 am     Reply with quote

Sice all memory is reserved for a tipial code, with (or without) stack, interrupt handling and so on, how can be two different sizes of occupied RAM? What does "worst case" means since there is no stack and memory required for all routines are well known? Which one is relevant?
icesynth



Joined: 03 Sep 2007
Posts: 32
Location: Edmonton, Alberta

View user's profile Send private message Visit poster's website

PostPosted: Wed Sep 05, 2007 8:20 am     Reply with quote

Use the "Worst Case" value.
_________________
Programming for the the real world.
--Chris Burchett
Sylver Technologies Inc.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: RAM used - worst case
PostPosted: Wed Sep 05, 2007 11:15 am     Reply with quote

Pret wrote:
Sice all memory is reserved for a tipial code, with (or without) stack, interrupt handling and so on, how can be two different sizes of occupied RAM? What does "worst case" means since there is no stack and memory required for all routines are well known? Which one is relevant?


Local variable are only active while the function they are declared within is active. Worst case then would be while running a function having many or large local variables.
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

Re: RAM used - worst case
PostPosted: Wed Sep 05, 2007 2:09 pm     Reply with quote

Neutone wrote:
Local variable are only active while the function they are declared within is active. Worst case then would be while running a function having many or large local variables.

I dont know what exactly do you mean with "active function", but since worst case is relevant what's the use of previous case? Also i could say 1 used byte of RAM... but worst case 500 bytes of RAM.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Sep 05, 2007 4:16 pm     Reply with quote

The key is in the difference from global declared variables and local variables.

On a 'normal' processor with a stack pointer the size of the data pushed onto the stack would vary depending on where you are in the program flow. Every nested function call and local variable would add to the size of the stack but returning from a function would decrease the stack size again.

The PIC processor has no hardware stack pointer, that's why many PIC compilers are assigning all variables to a fixed memory location. Compared to the competitors the CCS compiler is smart in this respect as it analyzes your source code for variables that are never used at the same time so it can 're-use' the memory location.
This re-use feature is where the 'minimum' and 'worst case' come from. The minimum memory is the amount of memory allocated to memory that is assigned to a single variable and at no point in time can be used by another variable, an example is a global variable.
The 'worst case' memory is more like a 'maximum' amount of memory used, i.e. the value of 'minimum' plus the total amount of 'local' variables. Subtract these two values and you get the maximum stack size value.


Example 1; 2 large global buffers
Code:
int8 buf1[50];
int8 buf2[50];

void func1()
{
  Buf1[0] = 1;
}

void func2()
{
  Buf2[0] = 1;
}

void main()
{
  int8 Local;
   
  func1();
  func2();
}
Ram used at main() level: 106
Worst case: 106
Both values are equal, it makes no sense at all to report two values as you are saying.


Example 2; the global buffers are now local to the function
Code:
void func1()
{
  int8 buf1[50];
 
  Buf1[0] = 1;
}

void func2()
{
  int8 buf2[50];

  Buf2[0] = 1;
}

void main()
{
  int8 Local;
   
  func1();
  func2();
}
Ram used at main() level: 6
Worst case: 56
Now both values are different. The mimimum RAM size is reduced to 6 bytes for CCS internal variables and the Local variable. The memory space for the Buf arrays can be re-used and worst-case RAM usage has dropped from 106 to 56 bytes.
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

PostPosted: Thu Sep 06, 2007 12:27 am     Reply with quote

I see... Practically, difference between those values are bytes available for other functions if you put them in main. Interesting...

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