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 

Switching from malloc() to sceKernelAllocPartitionMemory()

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



Joined: 22 Nov 2005
Posts: 11

PostPosted: Fri Feb 03, 2006 10:38 pm    Post subject: Switching from malloc() to sceKernelAllocPartitionMemory() Reply with quote

Hey guys and possibly gals :P

Does anyone know how I can do the equivalent of
Code:
firstpointball = malloc( sizeof(struct pointball) );
using the sceKernelAllocPartitionMemory (); function ??

I understand some of the variables it's asking for, but not sure what I should have in there for partitionid and name...

The snippet of code is creating a new node on a linked list, and because i'm using malloc I think it's affecting it's combatibility with 2.0+

Also, if Fanjita see's this thread, what limitations are there for programming 2.1+ or are they the same as 2.0 ?

thank you for looking...
Back to top
View user's profile Send private message
Fanjita



Joined: 28 Sep 2005
Posts: 217

PostPosted: Fri Feb 03, 2006 10:45 pm    Post subject: Reply with quote

Assuming that you want to allocate in user space, use partition ID = 2.

The name can be a char string of anything you want - just use something descriptive for each block. I'm not sure if they have to be unique.

malloc() vs AllocPartitionMem() shouldn't be a cause of problems on 2.01+ : the most likely problem at this stage of development is just bugs in the eLoader itself, it's very unstable still.
_________________
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
Back to top
View user's profile Send private message
Shatterdome



Joined: 22 Nov 2005
Posts: 11

PostPosted: Fri Feb 03, 2006 10:53 pm    Post subject: Reply with quote

Excellent, thank you very much for the quick reply.

So I guess once you've ironed out the wrinkles in the eloader then programming for 2.1 will be very similar to 1.5 (minus kernel access) ?

I'll still switch everything over to scemempartalloc to see if it helps anything though, can't hurt i'm sure :D

Thanks again...
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sat Feb 04, 2006 2:55 am    Post subject: Reply with quote

The only difference you are likely to find is there is probably a finite limit to the number of allocations you can make with sceKernelAllocPartitionMemory because each allocation creates a new UID with its associated information. Whether this limit is small enough to make a different I do not know.

With malloc it just allocates a large memory block to use as its heap and then handles the allocations internally so you are just limited by the malloc implementation. If all you are going to do is allocate a large block then chunk that up in a malloc like fashion I do not see the real benefit to using it over malloc.
Back to top
View user's profile Send private message
Fanjita



Joined: 28 Sep 2005
Posts: 217

PostPosted: Sat Feb 04, 2006 10:35 am    Post subject: Reply with quote

You'll probably also find that your libc has grabbed just about all of the AllocPartitionMemory heap at startup, to support malloc, so there won't be much left for AllocPartitionMemory.

There's a macro to set the size of the heap grabbed by newlib, though I forget the exact name - it shouldn't be hard to find.
_________________
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
Back to top
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Sat Feb 04, 2006 11:22 am    Post subject: Reply with quote

Code:
/* Define the main thread's heap size (optional) */
/**
 * ELF:
 * Elf default is (Max) available memory block
 *
 * PRX:
 * when making a prx, prx default heap size is (64K)
 * if youd like to use more change below *
 */
PSP_HEAP_SIZE_KB(size_KB)

_________________
10011011 00101010 11010111 10001001 10111010
Back to top
View user's profile Send private message
TheBrooster



Joined: 01 Jun 2005
Posts: 16

PostPosted: Sun Feb 05, 2006 1:32 am    Post subject: Reply with quote

To be honest, you are probably better writing your own allocator. At the start of your progam, allocate a big chunk of memory. Then whenever you wanna do any more allocations, just allocate out of that chunk.

Will also be faster that using malloc.
Back to top
View user's profile Send private message
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Sun Feb 05, 2006 6:33 pm    Post subject: Reply with quote

Dont use that function.

Use the sceKernelCreateFpl function (not sure if thats the exact spelling & capitalization)

Fpl = Fixed Pool

Theres also sceKernelAllocFpl which allocates inside of it. I'm fairly certain that CreateFpl internally calls AllocPartitionMemory, but Id still stay away from it.
Back to top
View user's profile Send private message AIM Address 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