Gurus, I was just wondering what could be the best possible way to calculate free memory while our code is running in SDRAM.I have used vxworks and it uses a approach to calculate the free memory as follows: Fill up the entire stack with 0xeeeee and then when you start using the stack,if at all a particular address in memory is used,the value of
0xeeeee in that location should be overwritten with real data.So if we are able to track the first occurance of the pattern 0xeeeee we should be able to subtract it from the entire size of memory and make a fair assesment of the available free memory.How ever I beleive such a algorithm has drawbacks.First drawback which I can think is
1)What is the guarentee that the real data is not ur pattern chosen(In vxworks case,its 0xeeeee,if 0xeeeee itself is real data,we cant find out real size!)?2)What should you look for to identify unique pattern?Or other way how would you arrive at the pattern word to be used?
3)Are there any other good techniques for calculating free memory?4)We are making software for a consumer electronics appliance.It uses a premitive propreitory RTOS which does not give enough tools to find out free memory.We are in a forced situation to reduce memory consumption,so we have to get a way to calculate free available memory first.To add to the complexity,our application uses heap,partitions,partition with in partitions.At any point of time we have to give the user memory utilised like most RTOS tools provide.Since Heap is dynamic how do u arrive at a fair judgment? If we wanted to get total free space,we need to calculate free space in heap,free space in partition and then arrive at it.
Are any one aware of any good way to achieve it in the given case of RTOS vendor not providing tools for memory calculations?
Looking farward for all your replys and Advanced thanks for the same.
Regards, s.subbarayan