Jump to content
Sign in to follow this  
Anguel

C2000 16 bit chars and strings waste memory

Recommended Posts

Hi!

 

Yesterday I learned to know that chars ("bytes") on C2000 are actually 16 bit words :-( Unfortunately this is a complete waste of memory when we just need a simple byte (8 bits). For example take the C2000 launchkit demo and look at the memory map for the ti_ascii char array constant defined in ti_ascii.h.

 

I wonder if there is an easy way to enter string constants so that they do not occupy twice the memory they actually need. The only way I can imagine is to enter them in HEX so that one 16 bit word actually contains two 8 bit chars. But this is very unfriendly as one has to type the hex code for each char instead of entering them as readable chars.

 

Regards,

Anguel

Share this post


Link to post
Share on other sites

Anguel,

You're absolutely right...our memory is 16 bits wide and in some applications this wastes space.  We are not really a general purpose micro-controller though.  The C2000 family of devices are more like mini DSPs and as such they are architected to perform best when doing complex math/control algorithms.

 

Like I said these devices really aren't designed for string manipulation, but you certainly could hack something together (as you suggested) to try to save some space.  I, however, do not know of a good way to do this currently in an automated fashion.

 

Trey

Share this post


Link to post
Share on other sites

Thank you for the feedback Trey. You are correct and I am afraid that the 32 KWords on the C2000 may be insufficient for more general-purpose embedded applications.

 

So I will reconsider if it is not more suitable to use a TI Cortex M4F instead. This approach looks more universal and if I understand correctly, the Stellaris peripheral drivers are mature in contrast to the C2000 peripheral drivers. Is this correct?

Share this post


Link to post
Share on other sites

You can use the __byte((int*)bufer, N) compiler "intrinsic" to access the Nth byte of a given buffer. That could make retrieval easier. However I don't think it would save any space when creating the array of chars because the litteral in 

 

__byte((int*)buffer, N) = 'a'; 

 

is probably still going to be stored in a 16 bit char.

 

You could still build the array by doing hex and then grabbing the Nth char with the __byte((int*)buffer, N) intrinsic.

 

As far as building the hex litterals for the array some excel or python magic could help.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

Sign in to follow this  

×
×
  • Create New...