Hi,
While malloc() seems to use mem1 .. how to properly allocate memory from mem2?
thx
alloc from mem2?
Re: alloc from mem2?
right now i'm assuming that SYS_GetArena2Lo() is returning usable memory. ^^
maybe we've got something a bit better?
maybe we've got something a bit better?
Re: alloc from mem2?
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) ^^
it doesn't seem that there is any kind of memory manager for mem2..
and yes we don't need that! (much) ^^
Re: alloc from mem2?
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
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
Re: alloc from mem2?
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).
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).
Who is online
Users browsing this forum: Ahrefs [Bot] and 2 guests