Best declaration of array of strings
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2012-07-14 8:09 AM
Posted on July 14, 2012 at 17:09
Hi all,
I am developping an application on 16K RAM device and I am facing limitation of RAM size so I want to optimize the definition of the following pointer to strings and I want to know if I am well understanding the stuffs When I define the array as following, the whole buffer (128 x string size) will be programmed in RAM: uint8_t* Buffer[128] = { ''STR1'', ''STR2'',.....}; When I define the array as folllowing, the whole buffe is programmed in flash memory and hence I optimized the RAM memory const uint8_t Buffer[128] [20]= { ''STR1'', ''STR2'',.....}; What do you think?MCU Lüfter
This discussion is locked. Please start a new topic to ask your question.
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2012-07-14 8:58 AM
Posted on July 14, 2012 at 17:58
static uint8_t const * const strtbl[] = {
''STR1'', ''STR2'', ''STR3'' }; The less fixed dimension you give it, the more leeway the compiler has to implement it most efficiently. static may be overkill, but limits the scope to a single object and thus decisions about how it might be exported or utilized/exploited by others are removed. It also helps isolate ''where used'' questions.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2012-07-16 10:09 PM
Posted on July 17, 2012 at 07:09
Did you try also
const uint8_t* Buffer[128] = { ''STR1'', ''STR2'',.....};
oruint8_t* const Buffer[128] = { ''STR1'', ''STR2'',.....};
orconst uint8_t* const Buffer[128] = { ''STR1'', ''STR2'',.....};
(Please recognize, that it is a significant difference, whether you place the const after or before the ''*'' - one time the Buffer contents is const, one time the Buffer pointer).