Jump to content
Sign in to follow this  
fred

Initializing Costs Rom Words...?!

Recommended Posts

I have an array of ints.

 

without initializing the array the linker reports free 40 words ROM

initializing costs 66 words...? <_<

 

uint	IRstream[15];  //  free 40 words

//changing the line above in
uint	IRstream[15]={
63507,3507,
63507,
63507,
63507,
63507,
63507,
63507,
63507,
63507,
63507,
63507,
0,0,0

};   // too much code to fit in ROM, overfilled with 20 locations....

 

??

Share this post


Link to post
Share on other sites

Hi fred,

 

Each non-zero byte that you put into your array will cost you 2 instructions (load and store). The zero byte store is just a clrf instruction.

 

Your array will cost 54 ROM locations to fill it up.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

huh....

 

that's new to me and I'm\ confused now. isn't this something which is done by the compiler when the aray space is preserved in the data area?

 

I thought that this is the major difference between defining

char *array and char array[15] where the first is only the pointer and the 2nd pointing to the allocated data space!

 

So defining a big character table doesn't only cost a lot of data space but even more code to have it initialized even when it's all static data?

Share this post


Link to post
Share on other sites

That sounds about right, I would expect to see the savings you expect if you initialized as a const, but I'm not sure what BoostC does.

 

I wonder if you made two arrays, one const in ROM and the other the uninitialized array in ram and then wrote your own copy if you could do it in less than 20 bytes. I suspect yes.

 

Jacob

Share this post


Link to post
Share on other sites

Dude,

 

Your array was declared as being in RAM which is why the compiler put it there.

 

You have to use the "rom" keyword if you want your data to be placed in ROM.

 

The snag is that BoostC does not allow int arrays in ROM. I hope this will be addressed soon in a future release. It is one of the downfalls of BoostC.

 

Accessing data in ROM is going to cost you more code space which will make you run out of code space as well.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

hm, put it in eeprom using #pragma and then move it to ram initially at runtime takes probably less space. ugly solution however.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...