This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Malloc

How do i use the 'malloc' function.

Can someone give me an example..

Thanks in advance...

Parents
  • 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

Reply
  • 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

Children
No data