gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > my own malloc

#56378 - ProblemBaby - Sat Oct 08, 2005 8:56 am

I want to try to code my own malloc/free functions. But how do I know what memory already are in use?

Thanks in advance

#56385 - Lord Graga - Sat Oct 08, 2005 9:26 am

I suggest that you use EWRAM for malloc functions, as IWRAM would be too small for your needs (I guess).

#56427 - ProblemBaby - Sat Oct 08, 2005 6:00 pm

Okey, but how do I know where I can place memory safely? Do ive to keep track of all static allocations as well?

for example:
if ive declared a static buffer in EWRAM how can I know where I can put my dynamically data safe?

#56444 - DekuTree64 - Sat Oct 08, 2005 8:11 pm

There should be some linker-defined variables telling where sections start/end. In the DevKitARM gba_cart.ld, __eheap_start is the one you want. It's defined after the .ewram and overlay sections.
You can use it like a regular external variable:
Code:
extern u32 __eheap_start;

void main()
{
    void *heapStart = (void*)__eheap_start;
        // Go all the way to the end of EWRAM
    u32 heapSize = 0x2040000 - __eheap_start;

    InitMemoryManager(heapStart, heapSize);
}

_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#56454 - ProblemBaby - Sat Oct 08, 2005 9:05 pm

oh yeah exactly what I wanted
thanks a lot!