0

Does the following code everything before calling a malloc() of stdlib (optlib)?

————-
#include

/* initialization, allocation of heap memory in .bss */
#define HEAP_SIZE 2000
static char heap_storage[HEAP_SIZE];

extern char *_heap_of_memory;
extern char *_last_heap_object;
extern char *_top_of_heap;

void init_heap( void ){
_heap_of_memory = heap_storage;
_last_heap_object = heap_storage;
_top_of_heap = heap_storage + sizeof(heap_storage) – 1;
}
—————

Open Source Tools Support edited question
Question is closed, new answers are not accepted
    • Hello,

      Thank you for reaching out to us!

      At this time, we are still looking into the issue you have raised and we do not have a definitive answer available at the moment.

      However, we are doing our best to provide you with accurate feedback as soon as possible.

      Thank you again for your patience and we will be reaching out to you soon!


      Thank you,
      Darius
      The GNU Tools Team

    • Hello,

      Thank you for your patience.

      By default, malloc() will work without any prior setup and thus the heap memory will be allocated after the end of .bss section.

      For example: if the end of .bss is 0x20060a28, calling malloc() will return a pointer to 0x20060a30.

      If you like to overwrite this and take control of where to place the heap, you should instead overwrite the _sbrk()/_sbrk_r() function.

      Also, we have noticed that you have posted another question with the same issue on the forum. If you opened that issue by mistake, would you like us to close it and continue answering in here?

      Thank you again for your patience and please, let us know if we can be of further assistance.


      Kind regards,
      The GNU Tools Team

    • Sorry, this post is duplicated and should be closed.
      (Please see for the other post with the same title.)