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

heap size

Is there any easy way to get the heap size after I call init_mempool and have called malloc several times. I want to see how much memory is left.
Mark

Parents
  • Is there any easy way to get the heap size after I call init_mempool and have called malloc several times.

    It depends on your definition of easy.

    Source code is provided for the memory allocation routines. You could write a routine that traverses the free blocks and adds the total free space.

    Probably more important than the total space unused is the size of the largest free block. That tells you how big of a thing you can allocate.

    A cool thing about the Keil memory allocation routines is that they merge adjacent free blocks. What that means is that if you allocate all available memory and then free it, you'll end up with the whole heap free instead of lots of little free blocks (like some memory allocation implementations do).

    Jon

Reply
  • Is there any easy way to get the heap size after I call init_mempool and have called malloc several times.

    It depends on your definition of easy.

    Source code is provided for the memory allocation routines. You could write a routine that traverses the free blocks and adds the total free space.

    Probably more important than the total space unused is the size of the largest free block. That tells you how big of a thing you can allocate.

    A cool thing about the Keil memory allocation routines is that they merge adjacent free blocks. What that means is that if you allocate all available memory and then free it, you'll end up with the whole heap free instead of lots of little free blocks (like some memory allocation implementations do).

    Jon

Children
No data