Switching from malloc() to sceKernelAllocPartitionMemory()

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

Moderators: cheriff, TyRaNiD

Post Reply
Shatterdome
Posts: 11
Joined: Tue Nov 22, 2005 6:49 pm

Switching from malloc() to sceKernelAllocPartitionMemory()

Post by Shatterdome »

Hey guys and possibly gals :P

Does anyone know how I can do the equivalent of

Code: Select all

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...
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

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!
Shatterdome
Posts: 11
Joined: Tue Nov 22, 2005 6:49 pm

Post by Shatterdome »

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...
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

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.
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

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!
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

Code: Select all

/* 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
TheBrooster
Posts: 16
Joined: Wed Jun 01, 2005 8:55 am

Post by TheBrooster »

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.
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

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.
Post Reply