alloc from mem2?

Post Reply
ozzyyzzo
Posts: 19
Joined: Wed Jun 03, 2009 7:23 pm
Location: greece

alloc from mem2?

Post by ozzyyzzo » Thu Jun 04, 2009 7:01 pm

Hi,

While malloc() seems to use mem1 .. how to properly allocate memory from mem2?
thx

ozzyyzzo
Posts: 19
Joined: Wed Jun 03, 2009 7:23 pm
Location: greece

Re: alloc from mem2?

Post by ozzyyzzo » Thu Jun 04, 2009 7:12 pm

right now i'm assuming that SYS_GetArena2Lo() is returning usable memory. ^^
maybe we've got something a bit better? :)

ozzyyzzo
Posts: 19
Joined: Wed Jun 03, 2009 7:23 pm
Location: greece

Re: alloc from mem2?

Post by ozzyyzzo » Fri Jun 05, 2009 10:12 pm

Ok then, using SYS_GetArena2Lo() base addy just works well..
it doesn't seem that there is any kind of memory manager for mem2..
and yes we don't need that! (much) ^^

shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: alloc from mem2?

Post by shagkur » Sat Jun 06, 2009 9:02 am

Hi,

latest SVN already contains a patch for malloc to handle mem2 aswell.
ofcourse mem2 will only be taken if we run out of mem1.

Also there's the lwp_heap API for custom memory management.

regards
shagkur

Beau
Posts: 6
Joined: Thu Aug 13, 2009 7:13 pm

Re: alloc from mem2?

Post by Beau » Thu Sep 10, 2009 11:54 pm

Becareful using this, a lot of memory goes to waste in certain instances due to internal fragmentation since MEM1 and MEM2 are not contiguous memory.

For example, the way memory is allocated with sbrk and the way Wii has 23 MB and 64 MB seperately leads to major internal fragmentation. If you were to allocate say 11 MB, and you only have 10 MB in MEM1, 11 MB will be allocated out of MEM2. You'd think that you would still have 10 MB in MEM1, however, you would be wrong. The 10 MB in MEM1 is treated as fragmented within sbrk/newlib malloc implemenations. MEM1 is not able to be used until all memory in MEM2 has been free'd (every last byte).

If you want the best possible use of memory, configure libogc to not malloc out of MEM2 (just MEM1) and write your own heap for MEM2 or use LWP_HEAP. This makes LibOGC have 2 heaps (which reflects the reality of the hardware design Nintendo decided) and avoids fragmentation easily. However, with this approach you typically have to hook malloc via -wrap in GCC and call __real_malloc yourself and if that fails, then allocate out of the LWP_HEAP (MEM2).

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests