forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Heap and Allocating More

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Tue Mar 10, 2009 10:23 am    Post subject: Heap and Allocating More Reply with quote

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
View user's profile Send private message MSN Messenger
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Tue Mar 10, 2009 7:19 pm    Post subject: Reply with quote

I don't think this heap is even the same as the heap used by libc stuff.
Back to top
View user's profile Send private message
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Wed Mar 11, 2009 9:00 pm    Post subject: Reply with quote

then what is it for
Back to top
View user's profile Send private message MSN Messenger
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Wed Mar 11, 2009 9:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Wed Mar 11, 2009 9:07 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Wed Mar 11, 2009 9:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Wed Mar 11, 2009 9:15 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Wed Mar 11, 2009 9:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Wed Mar 11, 2009 9:23 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Wed Mar 11, 2009 9:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Wed Mar 11, 2009 9:31 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Wed Mar 11, 2009 9:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Wed Mar 11, 2009 10:05 pm    Post subject: Reply with quote

ok cool thanks
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group