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

float const memory usage

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







float const memory usage
PostPosted: Fri Dec 12, 2003 3:56 am     Reply with quote

I have the following constant array:

float KHE[cells] = { LOG_2 / half_time_helium[0],
LOG_2 / half_time_helium[1],
LOG_2 / half_time_helium[2],
LOG_2 / half_time_helium[3],
LOG_2 / half_time_helium[4],
LOG_2 / half_time_helium[5],
LOG_2 / half_time_helium[6],
LOG_2 / half_time_helium[7],
LOG_2 / half_time_helium[8],
LOG_2 / half_time_helium[9],
LOG_2 / half_time_helium[10],
LOG_2 / half_time_helium[11],
LOG_2 / half_time_helium[12],
LOG_2 / half_time_helium[13],
LOG_2 / half_time_helium[14],
LOG_2 / half_time_helium[15]
};

When I include the CONST keyword, my ROM use drops from 11804 to 11678. My RAM use also drops from 874 to 749.

ROM used: 11678 (37%)
20254 (63%) including unused fragments


1) Why does the removal of the CONST keyword increase ROM usage?

2) What are the unused fragments about?

3) Why does moving a 16 element array of 4 byte values (64 bytes) to RAM increase RAM usage by 874-749=125 bytes.

My app is pushing the limits on all fronts - RAM, ROM, and cycles, so I'm trying to really understand what is going on here.

This is only part of the app that I am testing separately.

I am using 3.180 on an 18F452.
Ttelmah
Guest







Re: float const memory usage
PostPosted: Fri Dec 12, 2003 7:16 am     Reply with quote

bgpartr wrote:
I have the following constant array:

float KHE[cells] = { LOG_2 / half_time_helium[0],
LOG_2 / half_time_helium[1],
LOG_2 / half_time_helium[2],
LOG_2 / half_time_helium[3],
LOG_2 / half_time_helium[4],
LOG_2 / half_time_helium[5],
LOG_2 / half_time_helium[6],
LOG_2 / half_time_helium[7],
LOG_2 / half_time_helium[8],
LOG_2 / half_time_helium[9],
LOG_2 / half_time_helium[10],
LOG_2 / half_time_helium[11],
LOG_2 / half_time_helium[12],
LOG_2 / half_time_helium[13],
LOG_2 / half_time_helium[14],
LOG_2 / half_time_helium[15]
};

When I include the CONST keyword, my ROM use drops from 11804 to 11678. My RAM use also drops from 874 to 749.

ROM used: 11678 (37%)
20254 (63%) including unused fragments


1) Why does the removal of the CONST keyword increase ROM usage?

2) What are the unused fragments about?

3) Why does moving a 16 element array of 4 byte values (64 bytes) to RAM increase RAM usage by 874-749=125 bytes.

My app is pushing the limits on all fronts - RAM, ROM, and cycles, so I'm trying to really understand what is going on here.

This is only part of the app that I am testing separately.

I am using 3.180 on an 18F452.


When a value is defined as a constant, it is stored in ROM, and accessed (depending on the chip), either by using the tblrd ability (on the 18 family), or by using retlw calls on the 16 family. The routine to do this access is placed in front of the data.
When you declare it as a normal variable, the same storage has to take place (remember ROM is the only place to store a constant), and during boot, the code has to be added to return every value, and copy it to RAM.
The effect this will have on memory useage, will depend on how often the values are retrieved, and how the values are accessed. So (for instance), if you access an array with a constant address (array[0]), and this is stored in RAM, the bytes will be directly accessed, using very little code. However if you access using a variable (array[n]), then the calculation has to be performed to work out what value to retrieve, and this is bulkier. With a constant array, there is one permanently 'in place' function, to retrieve any value.
Hence, your reduction in ROM space, is because you do not need the extra initialisation code, and the accesses you have to the array are smaller for the ROM array, than for the RAM version.

Best Wishes
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