Hi Folks
I am trying to create a dynamic array in a function and pass a pointer to it to another function.
However when I run malloc() the compiler gives two warnings:
creating ".sysmem" section with default size of 0x400; use the -heap option to change the default size
function declared implicitly
both of which refer to the malloc instruction which is as below:
sciFifoTxBuf = (Uint16*) malloc(sizeof(Uint16));
Im guessing that maybe there is some different way to achieve this functionality in flash in CCS?
Appreciate a point in the right direction
Ta
Hi Toby,
For the first warning, take a look at you linker command file. Do you have a .sysmem section defined and linked into RAM? If not take a look at the linker command files provided in controlsuite and try using one that does.
The second warning you are getting because you aren't including the right header file. Try including stdlib.h.
Keep in mind that dynamically allocated memory must be in RAM, not flash.
Regards,
Trey
Trey German
C2000 Applications
Trey GermanKeep in mind that dynamically allocated memory must be in RAM, not flash.
Also keep in mind that dynamic memory allocation is often best avoided in embedded systems.
Why, specifically, do you think that you need dynamic allocation?
++ to Andy's comment!!!
Thanks for the comments. The reason for the dynamically allocated memory is for reading in data received on communications peripherals, in this case the SCI.
Information transmitted on the SCI could be of any length, and I plan, at a later stage, to implement an SCPI parser on the device to pass instructions to it from a parent control system, so the data string coming in could again be very short or relatively very long.
While i can see that there needs to be a limit on the amount of memory allowed to be dynamically allocated for a specific task for only the short time that the task requires it, it would be a waste to set a some long length as the maximum number of characters and permanently reserve that space in memory, thus for embedded systems that have less memory than is available to computer applications, I would have thought this approach to be the more desirable one...
Though I guess if thats the way it should be done, then thats the way it should be done.
Trey, f I was to use dynamically allocated memory how would I ensure that it be allocated in RAM instead of flash?
Thanks
Toby Moleit would be a waste to set a some long length as the maximum number of characters and permanently reserve that space in memory
But that is exactly what you have to do in order to support dynamic allocation - it is called The Heap!!
And, not only do you have to reserve that memory, but you also make less efficient use of it - due to the overheads of manging the dynamic allocation.
And you add the issues of having to deal with fragmentation, etc...
On the issue of fragmentation: when the CPU is reset does that act as an indirect "defragmentation" of that memory location since the heap is located in RAM?
Is this a true statement?"
Toby,
Memory allocation is handled in the linker command files (*.cmd). I'm not sure off the top of my head which section the heap is placed in, but the assembly language tools user guide could probably tell ya.
Derek,
Yes, a CPU reset would effectively defragment the RAM as all of the variables that kept track of allocation would be reinitialized. Data may still be present in RAM, but it won't be usable because the program execution wouldn't be aware of it.