Heap and Allocating More

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Heap and Allocating More

Post by coolkehon »

i saw this function and i was wondering can i allocate more heap like it says and if so what good does it do me could i reallocate the currently used heap defined from PSP_HEAP_SIZE(-5000)

Code: Select all

SceUID 	sceKernelCreateHeap (SceUID partitionid, SceSize size, int unk, const char *name)
void * 	sceKernelAllocHeapMemory (SceUID heapid, SceSize size)
how can i effectively use these so i can allocate more memory for my prx/eboot or use
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

I don't think this heap is even the same as the heap used by libc stuff.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

then what is it for
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Instead of sceKernelAllocPartitionMemory which allocates a free memory block from raw memory partition (which has some memory overhead for each allocation and is inefficient for multiple allocations), you can allocate a big heap from the raw partition and sceKernelAllocHeapMemory will sub-allocate from the heap more efficiently.

I don't know about the internal workings of PSPSDK, but just as a wild guess, maybe it creates a heap with this same function and malloc and stuff is redirected to that heap. So if you knew the heapid you might be able to resize it. Just a guess.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

well if i can get the heap id or i already have a heap then how can i realloc an already existing heap i didnt see any reallocate for it
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

coolkehon wrote:well if i can get the heap id or i already have a heap then how can i realloc an already existing heap i didnt see any reallocate for it
I didn't see any resize function either :P

Basically PSP_HEAP_SIZE(x) is analogous to heapid=sceKernelCreateHeap(2, x, ...);
And malloc(y) is like sceKernelAllocHeapMemory(heapid, y);
Last edited by Torch on Wed Mar 11, 2009 9:21 pm, edited 1 time in total.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

oh ok so i was confused sceKernelAllocMemory allocates from all the free memory the psp has in the partion id and sceKernelAllocHeapMemory allocates memory from a heap well then how would i set malloc to allocate memory from another heap
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

coolkehon wrote:oh ok so i was confused sceKernelAllocMemory allocates from all the free memory the psp has in the partion id and sceKernelAllocHeapMemory allocates memory from a heap well then how would i set malloc to allocate memory from another heap
It would probably prove problematic. The PSPSDK doesn't allocate the heap from the partition until the first time you allocate memory using malloc or whatever. Until then all the memory in the partition will be free. So if you never use malloc, you can create your own heap with the sce functions and allocate using the sce functions.

Unless there is some way to change the heapid that the PSPSDK uses in malloc, you probably can't delete it's heap and create a different sized one at runtime. Assuming that it even uses the sce functions to create a heap in the first place.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

so where do things like local variables and functions and function calls go in memory are they also in the same heap

also oslib crashes when i call oslInitGfx and there isnt enouph memory so i was hoping to fix this somehow
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

coolkehon wrote:so where do things like local variables and functions and function calls go in memory are they also in the same heap

also oslib crashes when i call oslInitGfx and there isnt enouph memory so i was hoping to fix this somehow
Variables and functions declared in the code are statically allocated in memory when the executable is loaded by the OS. The remaining memory in the partition after this is available for allocation as a heap or whatever.

I have no idea about oslib.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

i believe oslib is using some malloc and isnt allocating heap

if i dont have any heap like PSP_HEAP_SIZE(0); will my program still work if there is no malloc used at all
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

You don't need a heap unless you allocate. If there is insufficient or no heap, then malloc will return an error.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

ok cool thanks
Post Reply