This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Memory alignment optimization

Hello,

I am having issues with the memory allocation on an F28035. The variables are not stored as close to each other as possible.

I attached a capture of the memory browser for reference. I filled up the memory with 0xBEEF to see the memory utilization. memEnd and memfree_ptr are 32-bit variables. However, the memory is padded with an additional 60 words before the next variable (mempool). Is there a way to modify the page alignment to optimize for memory usage? I am using optimization level 0, but I also tried level 3, with no changes in the memory alignment.

I am using CCS v5.3 and the compiler is TI v6.1.4. I tried using the latest compiler (TI v.15.12.0), but the result is the same.

Thanks.

  • Juan,

    On C28x there is a 6-bit data page pointer, so we have 64 words per page.  0x98C0 and 0x9900 are both data page boundaries.

    Your 32-bit variables are on the same data page, as they should be, but for some reason mempool is being aligned on the next page.  What is "mempool" please?

    Can you supply the variable declarations and also the "MEMORY" part of your linker command file?  Thanks.

    Regards,

    Richard

  • Hi Richard,

    mempool is a vector. The declarations are as below:

    static unsigned char * memfree_ptr;
    static unsigned char * memEnd;
    unsigned char mempool[300];

    The variables are allocated in static memory (.ebss)

    .ebss : > RAML0123 PAGE = 1

    where:

    RAML0123 : origin = 0x008150, length = 0x001EB0 /* on-chip RAM block L0/1/2/3, (8k - 0x150) */
  • Hi Juan,

    The algorithm the linker uses for placing variables in memory tries to fit each variable into the smallest "hole" on a data page.  Where a variable exceeds a data page size (i.e. is greater than 64-words) the variable is aligned on a data page boundary.  In your case, "mempool" has 300 16-bit elements.  It therefore spans four data pages, so the linker places the start address on a 64-word boundary.  The vector fills three contiguous data pages and all but 20 words of a fourth.  That's the intended and default behavior.

    There are several ways of controlling section placement if you want something different.  All this is in chapter 8 of the Assembly Tools Guide:

    http://www.ti.com/lit/ug/spru513j/spru513j.pdf

    Regards,

    Richard