Save array data in code segment

jan233321
2006-06-25
2006-07-14
  • jan233321 - 2006-06-25

    Hi all,

    I'm trying to create constant arrays of bytes. If I use global variables and VAR_CONSTANT, it looks like:

    code in ST:

    generated code:

    255 times. If you have more than 1 array then more times... .

    This code is not very optimised, it is consuming a large amount of code memory (1 array item needs 12 bytes of code memory).

    Does exist any possibility to create this array directly in program memory segment (in flash - any pragma)? Next step is to create one small loop to copy data from flash to ram.

    Thans

    Jan

     
  • Igor Petrov - 2006-07-14

    The generated code belongs to initialization section executed only once. Therefore intensive optimization in it is not important for the program speed.

    If you have few memory and really need to optimize code by size then you may try the next trick. I used it for 8051 system with tiny memory.

    1) You can declare string instead of BYTE array. For example:

    It have to generate compact string in code memory with compact mem copy function for initialization.

    2) There are 2 methods to use a string like an rray. A) Declare both the string and the array on the same address in 'M' memory; B) Make pointer to the array and set it to ADR of the string.

    Regards

     

Log in to post a comment.