We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
How do i use the 'malloc' function. Can someone give me an example.. Thanks in advance...
You are all right that malloc and free are usually bad for embedded systems. The memory allocation routines from Keil are a direct implementation of the Knuth memory allocations described in "The Art of Computer Programming". The most important part of this implementation (in my opinion) is that the free function re-joins adjacent free memory blocks. So, for example, you can allocate all of the memory (in small pieces), free it all, and then allocate a big block -- and it will work! You must provide the address and size of the heap to the memory allocation initialization code. This is easiest done by creating a large array and passing the address and the sizeof the array. Anyway, with a little forethought and management, you can use malloc/free in an embedded program. Jon