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.

DS development > Just using 'malloc'

#123146 - MrD - Sun Mar 25, 2007 5:24 pm

On the DS, is it okay to use malloc and free as one would normally do when coding for the PC?

Is there any caveats that I should be aware of? (Or can I just malloc and free like crazy until I fill or fragment the memory to buggery?)
_________________
Not active on this forum. For Lemmings DS help see its website.

#123147 - simonjhall - Sun Mar 25, 2007 5:30 pm

Should be fine. It's what I use!
Couple of things you should be aware of though:
a) if you're gonna be using the extra memory provided by some of the slot-2 cards at some point, you're probably gonna wanna wrap malloc so you can control which memory space it goes to. When I use slot-2 RAM I also use a different memory allocator, as I don't know how to tell the existing malloc that I've got two spaces

b) malloc on the ARM7 may be slightly hairy, as I'm sure the heap points at the 96k of fast RAM. If you want to malloc from the main memory block you've gotta do something a bit more complicated.

That's about it, I think.
_________________
Big thanks to everyone who donated for Quake2

#123152 - ikaris - Sun Mar 25, 2007 5:44 pm

While this may not be perfect down the smallest percentile, I use this to keep track of how much memory I've used up.

Use at your own risk !

I'm sure someone can think of a better / cleaner way to do this.

Code:
struct mallinfo mi = mallinfo();

float memFreePercent = ((float)mi.uordblks / 4000000.0) * 100;

iprintf("Memory Free: %d/100\n", (int)memFreePercent);