Hi, I have a system profile structure (set of system properties), saved in a serial dataflash. Size of a profile is about 16K. At power-up I need to extract from this profile another structure - slave profile (6K), and send it to the slave microcontroller over CAN. In order to do that at a certain point I need to initialize both structures in ram. And this is the only time when these structures are used.
The question is - what is the optimum way to allocate memory for these structures ? I am using STM32F107 with 64K of ram. If I initialize structures locally, in a 'parsing / slave initializing' function, I need to assign additional 22K to the stack, and I loose them for the application. By initializing these structures globally I also loose 22K of ram.
Would really appreciate considerations on this subject.
Gennady
I need to assign additional 22K to the stack, and I loose them for the application.
Not exactly. If other parts of your application use the stack extensively, then you don't loose it.
By initializing these structures globally I also loose 22K of ram.
Yes. If you don't reuse this memory in any way.
The question is: are you short on RAM? Do you need to worry at all? 64KB is plenty for many applications. If you really are short on RAM, you can try a few things: 1) Optimize memory-hungry algorithms. Are you sure you have to hold those structures in RAM? 2) Reuse memory. That means you have to figure out if other parts of your application can use the same memory. If it's possible, the next step is to choose how to share this memory: using the stack, or perhaps dynamic memory.
I need to assign additional 22K to the stack, and I loose them for the application. Not exactly. If other parts of your application use the stack extensively, then you don't loose it.
I can use part of this stack in other parts, but definitely not that much. And significant part of this application is a communication with multiple slaves / ethernet, so i need quite a few global buffers placed in ram. And again, the only purpose for placing this structures in ram is parsing structure. I really would like to avoid dynamic memory allocation, so I can try some other way to share memory.