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.

How can I declare uninitialized memory for use in heaps?

Background:  I'm using TI compiler v5.2.6 in CCSv6.1 with Processor SDK RTOS for AM335x with SYS/BIOS kernel.

I want to create a large heap (using HeapMem or HeapBuf) of around 400MiB.  However, this means that the underlying 400MiB buffer is being declared statically and placed in .bss, and thus the application spends a lot of time zero-initializing this memory during startup.  I know this because if I add '--zero_init=off' to the link line, then the startup delay disappears.  However, I'd rather not disable zerio-initialization for everything, especially since heaps aren't suppose to waste time giving you zeroed memory.

My question:  Is there a way to selectively disable zero-initialization only for certain variables?  

  • I figured out one way to do it:

    Declare your own linker section with type = NOINIT:

    var heapSection = new Program.SectionSpec();
    heapSection.loadSegment = "DDR3";
    heapSection.type = "NOINIT";
    Program.sectMap[".noinit"] = heapSection;

    and then use compiler pragmas when declaring the variables that should not be initialized:

    #ifdef __TI_COMPILER_VERSION__
      #define PRAGMA(x) _Pragma(#x)
      #define VAR_IN_SECTION(var, section) \
         PRAGMA(DATA_SECTION(var, #section))
    #else
      #define VAR_IN_SECTION(var, section)
    #endif
    
    VAR_IN_SECTION(heap_buffer, .noinit)
    static int heap_buffer[HEAP_SIZE/sizeof(int)];

    If there is a better/cleaner way, I would still love to hear about it.

  • Hi Brian,

    Glad you figured it out. You can also configure your heap to be placed in the section you created - heapSection - from within the configuration file, too.

    For example, if you are using a HeapMem heap, then the following code could be used (in addition to what you have already):

    var heapMemParams = new HeapMem.Params;

    heapMemParams.sectionName = "heapSection";

    Program.global.myHeap = HeapMem.create(heapMemParams);

    Please refer to the SYS/BIOS User's Guide, Chapter 7, Memory, for more details.

    Steve