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

Simple question probably..

I have define my heap in the startup.s
Heap_Size EQU 0x00001032

In a function I use:
void SST25_EditEXTStr(...)
{ unsigned char *buffer;

buffer = malloc(0x1000);

if (buffer != NULL) {

//do my stuff

free(buffer);

}
}

How come I can not set my Heap_Size to 0x00001000. If I do the buffer will be NULL

Thnx

Parents
  • Thank you for your reply.

    I have tried to minimalize the heap size by trie and error :-S and a oversize of 32 bytes was the minimun on which it still worked.

    My conclusion was the same as yours, I hope someone can tell me how much overhead it uses per malloc().

    I now think I have to use 32bytes extra on every malloc()

    meaning:
    buffer = malloc(0x100);
    buffer = malloc(0x1000);

    needs a heap_size of 0x1164.

    could this be correct? Or am I thinking crappy..

Reply
  • Thank you for your reply.

    I have tried to minimalize the heap size by trie and error :-S and a oversize of 32 bytes was the minimun on which it still worked.

    My conclusion was the same as yours, I hope someone can tell me how much overhead it uses per malloc().

    I now think I have to use 32bytes extra on every malloc()

    meaning:
    buffer = malloc(0x100);
    buffer = malloc(0x1000);

    needs a heap_size of 0x1164.

    could this be correct? Or am I thinking crappy..

Children
  • 0x1164 would represent an overhead of 0x64 which in decimal is 100 bytes.

    But do you really need a heap? Can't your program perform static allocations on startup, i.e. normal zero-initialized variables of potentially large size? Then you will not need any overhead at all, and the linker will not need to link in the heap code.