| View previous topic :: View next topic |
| Author |
Message |
Shatterdome
Joined: 22 Nov 2005 Posts: 11
|
Posted: Fri Feb 03, 2006 10:38 pm Post subject: Switching from malloc() to sceKernelAllocPartitionMemory() |
|
|
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 |
|
 |
Fanjita
Joined: 28 Sep 2005 Posts: 217
|
Posted: Fri Feb 03, 2006 10:45 pm Post subject: |
|
|
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 |
|
 |
Shatterdome
Joined: 22 Nov 2005 Posts: 11
|
Posted: Fri Feb 03, 2006 10:53 pm Post subject: |
|
|
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 |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Sat Feb 04, 2006 2:55 am Post subject: |
|
|
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 |
|
 |
Fanjita
Joined: 28 Sep 2005 Posts: 217
|
Posted: Sat Feb 04, 2006 10:35 am Post subject: |
|
|
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 |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Sat Feb 04, 2006 11:22 am Post subject: |
|
|
| 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 |
|
 |
TheBrooster
Joined: 01 Jun 2005 Posts: 16
|
Posted: Sun Feb 05, 2006 1:32 am Post subject: |
|
|
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 |
|
 |
CyberBill
Joined: 26 Jul 2005 Posts: 86 Location: Redmond, WA
|
Posted: Sun Feb 05, 2006 6:33 pm Post subject: |
|
|
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 |
|
 |
|