| View previous topic :: View next topic |
| Author |
Message |
coolkehon
Joined: 20 Oct 2008 Posts: 355
|
Posted: Tue Mar 10, 2009 10:23 am Post subject: Heap and Allocating More |
|
|
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: | 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 |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Tue Mar 10, 2009 7:19 pm Post subject: |
|
|
| I don't think this heap is even the same as the heap used by libc stuff. |
|
| Back to top |
|
 |
coolkehon
Joined: 20 Oct 2008 Posts: 355
|
Posted: Wed Mar 11, 2009 9:00 pm Post subject: |
|
|
| then what is it for |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Wed Mar 11, 2009 9:03 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
coolkehon
Joined: 20 Oct 2008 Posts: 355
|
Posted: Wed Mar 11, 2009 9:07 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Wed Mar 11, 2009 9:12 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
coolkehon
Joined: 20 Oct 2008 Posts: 355
|
Posted: Wed Mar 11, 2009 9:15 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Wed Mar 11, 2009 9:19 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
coolkehon
Joined: 20 Oct 2008 Posts: 355
|
Posted: Wed Mar 11, 2009 9:23 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Wed Mar 11, 2009 9:27 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
coolkehon
Joined: 20 Oct 2008 Posts: 355
|
Posted: Wed Mar 11, 2009 9:31 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Wed Mar 11, 2009 9:44 pm Post subject: |
|
|
| You don't need a heap unless you allocate. If there is insufficient or no heap, then malloc will return an error. |
|
| Back to top |
|
 |
coolkehon
Joined: 20 Oct 2008 Posts: 355
|
Posted: Wed Mar 11, 2009 10:05 pm Post subject: |
|
|
| ok cool thanks |
|
| Back to top |
|
 |
|