| View previous topic :: View next topic |
| Author |
Message |
gloupygloup
Joined: 12 May 2005 Posts: 9
|
Posted: Thu May 12, 2005 3:34 am Post subject: malloc newbie question |
|
|
Hi there,
im trying to build a little things on my own but im not familiar with the PS2SDK.I can compile the HelloWorld sample, make some change, have it running but when i want to make an allocation like :
int *data;
data = malloc(1024);
it compile but the compiler tell me undefined refence for malloc, i think that i miss to link a library but wich one contains the standard stdlib function ?
Thanks in advance ! |
|
| Back to top |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
|
| Back to top |
|
 |
gloupygloup
Joined: 12 May 2005 Posts: 9
|
Posted: Thu May 12, 2005 3:43 am Post subject: |
|
|
Thanks, of course i have added the malloc.h ;-) but not the -lc
im going to test that right away.
Thanks ! |
|
| Back to top |
|
 |
Orion_
Joined: 27 Jan 2005 Posts: 69
|
Posted: Thu May 12, 2005 3:49 am Post subject: |
|
|
how could the malloc of the standard libc would know where is the psp user ram and so on ??
I don't think this will work. |
|
| Back to top |
|
 |
gloupygloup
Joined: 12 May 2005 Posts: 9
|
Posted: Thu May 12, 2005 3:52 am Post subject: |
|
|
| Orion_ : i have checked your plasma wich work fine dont you alloc anything in memory ? |
|
| Back to top |
|
 |
Orion_
Joined: 27 Jan 2005 Posts: 69
|
Posted: Thu May 12, 2005 3:54 am Post subject: |
|
|
no :/
I compute the plasma picture in realtime inside the vram directly. |
|
| Back to top |
|
 |
gloupygloup
Joined: 12 May 2005 Posts: 9
|
Posted: Thu May 12, 2005 3:58 am Post subject: |
|
|
| hmm ok , i m going to do something about that so. |
|
| Back to top |
|
 |
Klesk
Joined: 02 Apr 2005 Posts: 4
|
Posted: Thu May 12, 2005 4:05 am Post subject: |
|
|
| i suppose the guy who made the gameboy emulator knows how to allocate memory |
|
| Back to top |
|
 |
sq377

Joined: 11 Apr 2005 Posts: 87
|
Posted: Thu May 12, 2005 4:19 am Post subject: |
|
|
| yea but he also doesn't know english very well. |
|
| Back to top |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Thu May 12, 2005 4:32 am Post subject: |
|
|
Oops, I thought this was a PS2-related question. Sorry. :)
Why not just statically declare the memory?
int data[1024]; |
|
| Back to top |
|
 |
subbie
Joined: 05 May 2005 Posts: 122
|
Posted: Thu May 12, 2005 4:51 am Post subject: |
|
|
| ooPo wrote: | Oops, I thought this was a PS2-related question. Sorry. :)
Why not just statically declare the memory?
int data[1024]; |
Thats all fine for a temp fix but a form of mallocing will be needed.
Anybody know if the systems ram can be directly address or does one need to call on the bios to allocate a useable heap from main memory? |
|
| Back to top |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Thu May 12, 2005 5:00 am Post subject: |
|
|
| It may be a little early in the life of the pspdev world to demand things like malloc. |
|
| Back to top |
|
 |
subbie
Joined: 05 May 2005 Posts: 122
|
Posted: Thu May 12, 2005 5:21 am Post subject: |
|
|
| ooPo wrote: | | It may be a little early in the life of the pspdev world to demand things like malloc. |
Agreed but i'm not going to just sit around and want want want. Questioning then researching will do wonders. :) |
|
| Back to top |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Thu May 12, 2005 5:27 am Post subject: |
|
|
| You bring a tear to my eye with such lovely words. :) |
|
| Back to top |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Thu May 12, 2005 6:02 am Post subject: |
|
|
| ooPo wrote: | | It may be a little early in the life of the pspdev world to demand things like malloc. |
With a little research I found this: http://forums.ps2dev.org/viewtopic.php?p=11133#11133. sceKernelAllocPartitionMemory() looks like malloc() to me. |
|
| Back to top |
|
 |
gloupygloup
Joined: 12 May 2005 Posts: 9
|
Posted: Thu May 12, 2005 7:07 am Post subject: |
|
|
well i need dynamic allocation since that i have make a couple of emulator and i would like to give it a try to port them into PSP.
Im going to find a way around this problem but it will ugly :D |
|
| Back to top |
|
 |
gloupygloup
Joined: 12 May 2005 Posts: 9
|
Posted: Thu May 12, 2005 7:31 am Post subject: |
|
|
Just for information i have tried the sceKernelAllocPartitionMemory like that :
| Code: |
data = (int*)sceKernelAllocPartitionMemory(sizeof(int)*20);
int i;
data[0] = 0xFFFF;
pgFillvram(0);
while(1) {
pgPrint4(1,1,0xFFFF,"TESTING");
pgScreenFlipV();
}
|
when i run my code to the PSP i have black screen but when i comment data[0] = 0xFFFF; i have "TESTING" displayed correctly
I have added this at the end of the startup.s :
| Code: | STUB_START "SysMemUserForUser",0x40000000,0x00030005
STUB_FUNC 0x237DBD4F,sceKernelAllocPartitionMemory
STUB_FUNC 0xB6D61D02,sceKernelFreePartitionMemory
STUB_FUNC 0x9D9A5BA1,sceKernelGetBlockHeadAddr
STUB_END
|
|
|
| Back to top |
|
 |
gloupygloup
Joined: 12 May 2005 Posts: 9
|
Posted: Thu May 12, 2005 7:40 am Post subject: |
|
|
| Edit : post deleted ( wrong manipulation = double post ) |
|
| Back to top |
|
 |
Shito
Joined: 11 May 2005 Posts: 21
|
Posted: Thu May 12, 2005 8:04 am Post subject: |
|
|
| gloupygloup wrote: | | when i run my code to the PSP i have black screen but when i comment data[0] = 0xFFFF; i have "TESTING" displayed correctly |
Well then that means that sceKernelAllocPartitionMemory returned null.
Either the memory could not be allocated because there wasn't enough free memory (I highly doubt that ^^), either there was something wrong with the function.
Now *what* is another question. '__'
(and that's all for the most useless and trivial post ever :| ) |
|
| Back to top |
|
 |
gloupygloup
Joined: 12 May 2005 Posts: 9
|
Posted: Thu May 12, 2005 8:08 am Post subject: |
|
|
I wonder if you dont have to give the pointer to your variable to sceKernelAllocPartitionMemory and that it return only OK or ERROR.
im going to have a try |
|
| Back to top |
|
 |
tonymoon
Joined: 10 May 2005 Posts: 4
|
Posted: Thu May 12, 2005 12:55 pm Post subject: |
|
|
| gloupygloup wrote: | Just for information i have tried the sceKernelAllocPartitionMemory like that :
| Code: |
data = (int*)sceKernelAllocPartitionMemory(sizeof(int)*20);
int i;
data[0] = 0xFFFF;
pgFillvram(0);
while(1) {
pgPrint4(1,1,0xFFFF,"TESTING");
pgScreenFlipV();
}
|
when i run my code to the PSP i have black screen but when i comment data[0] = 0xFFFF; i have "TESTING" displayed correctly
I have added this at the end of the startup.s :
| Code: | STUB_START "SysMemUserForUser",0x40000000,0x00030005
STUB_FUNC 0x237DBD4F,sceKernelAllocPartitionMemory
STUB_FUNC 0xB6D61D02,sceKernelFreePartitionMemory
STUB_FUNC 0x9D9A5BA1,sceKernelGetBlockHeadAddr
STUB_END
|
|
When i run your code my psp got frozen. I try anthor way like this code
| Code: |
int sceKernelAllocPartitionMemory(void* buf,int size);
void sceKernelFreePartitionMemory(void* buf);
|
and I failed too. |
|
| Back to top |
|
 |
Guest
|
Posted: Thu May 12, 2005 3:48 pm Post subject: |
|
|
| subbie wrote: | | ooPo wrote: |
Why not just statically declare the memory?
int data[1024]; |
Thats all fine for a temp fix but a form of mallocing will be needed.
Anybody know if the systems ram can be directly address or does one need to call on the bios to allocate a useable heap from main memory? |
Then roll your own dyamic memory allocator. Start with Oopo's suggestion to create your own heap, then write code to alloc, dealloc, realloc, and manage all of it. That will get you going until the time any real allocator is found.
You have no excuse to whine about this. Go forth and code, or wait for deliverance. :) |
|
| Back to top |
|
 |
gloupygloup
Joined: 12 May 2005 Posts: 9
|
Posted: Thu May 12, 2005 6:21 pm Post subject: |
|
|
Hehe,
i have find a way around and im starting getting things to show.
Soon as i got something i will post it here. |
|
| Back to top |
|
 |
|