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

When I setup memory pool beginning with 0x0000, malloc doesn't work.

When:

init_mempool(0x0000, 1024);
p = malloc(10);
malloc always returns NULL.
But when:
init_mempool(0x2000, 1024);
p = malloc(10);
p gets a valid address.
Why does this happen?
Thanks.

Parents Reply Children
  • I'm thinking why init_mempool doesn't do that for me

    init_mempool() is just a C function. It can't do anything until the code is running on your hardware.

    Allocating variables to particular addresses, however, is done by the linker, before the code ever starts running. The addresses of variables are embedded into the code. You need to tell the linker where you plan to put the heap, so that it can be sure to keep other variables out of that address range.

  • Yes. When I try to modify the source code of init_mempool to provide the function reserving the memory heap, it's obvious that I can't accomplish that, just as what you've pointed out.