2012-07-14 08:09 AM
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üfter2012-07-14 08:58 AM
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.2012-07-16 10:09 PM
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).