SPRU514Z July 2001 – October 2023 SM320F28335-EP
The run-time-support library supplied with the C28x compiler contains several functions (such as malloc, calloc, and realloc) that allow you to allocate memory dynamically for variables at run time.
Memory is allocated from a global pool, or heap, that is defined in the .esysmem or .sysmem section. You can set the size of the .esysmem or .sysmem section by using the --heap_size=size option with the linker command. The linker also creates a global symbol, __SYSMEM_SIZE (for COFF) or __TI_SYSMEM_SIZE (for EABI),, and assigns it a value equal to the size of the heap in words. The default size is 1K words. For more information on the --heap_size option, see the linker description chapter in the TMS320C28x Assembly Language Tools User's Guide.
If you use any C I/O function, the RTS library allocates an I/O buffer for each file you access. This buffer will be a bit larger than BUFSIZ, which is defined in stdio.h and defaults to 256. Make sure you allocate a heap large enough for these buffers or use setvbuf to change the buffer to a statically-allocated buffer.
Dynamically allocated objects are not addressed directly (they are always accessed with pointers) and the memory pool is in a separate section (.esysmem or .sysmem). Therefore, the dynamic memory pool size may be limited only by the amount of memory in your system. To conserve space in the .ebss or .bss section, you can allocate large arrays from the heap instead of defining them as global or static. For example, instead of a definition such as:
struct big table[100];
Use a pointer and call the malloc function:
struct big *table
table = (struct big *)malloc(100*sizeof(struct big));
When allocating from a heap, make sure the size of the heap is large enough for the allocation. This is particularly important when allocating variable-length arrays. For example, allocating a variable-length array requires at least 1500 words of heap memory.