malloc newbie question
-
- Posts: 9
- Joined: Thu May 12, 2005 3:28 am
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 !
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 !
Try including malloc.h:
http://cvs.ps2dev.org/cgi-bin/viewcvs.c ... .h?rev=1.5
The function itself would be in the libc library, so make sure you have a -lc on your link line.
http://cvs.ps2dev.org/cgi-bin/viewcvs.c ... .h?rev=1.5
The function itself would be in the libc library, so make sure you have a -lc on your link line.
-
- Posts: 9
- Joined: Thu May 12, 2005 3:28 am
-
- Posts: 9
- Joined: Thu May 12, 2005 3:28 am
-
- Posts: 9
- Joined: Thu May 12, 2005 3:28 am
Thats all fine for a temp fix but a form of mallocing will be needed.ooPo wrote:Oops, I thought this was a PS2-related question. Sorry. :)
Why not just statically declare the memory?
int data[1024];
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?
With a little research I found this: http://forums.ps2dev.org/viewtopic.php?p=11133#11133. sceKernelAllocPartitionMemory() looks like malloc() to me.ooPo wrote:It may be a little early in the life of the pspdev world to demand things like malloc.
-
- Posts: 9
- Joined: Thu May 12, 2005 3:28 am
-
- Posts: 9
- Joined: Thu May 12, 2005 3:28 am
Just for information i have tried the sceKernelAllocPartitionMemory like that :
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: Select all
data = (int*)sceKernelAllocPartitionMemory(sizeof(int)*20);
int i;
data[0] = 0xFFFF;
pgFillvram(0);
while(1) {
pgPrint4(1,1,0xFFFF,"TESTING");
pgScreenFlipV();
}
I have added this at the end of the startup.s :
Code: Select all
STUB_START "SysMemUserForUser",0x40000000,0x00030005
STUB_FUNC 0x237DBD4F,sceKernelAllocPartitionMemory
STUB_FUNC 0xB6D61D02,sceKernelFreePartitionMemory
STUB_FUNC 0x9D9A5BA1,sceKernelGetBlockHeadAddr
STUB_END
-
- Posts: 9
- Joined: Thu May 12, 2005 3:28 am
Well then that means that sceKernelAllocPartitionMemory returned null.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
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 :| )
-
- Posts: 9
- Joined: Thu May 12, 2005 3:28 am
When i run your code my psp got frozen. I try anthor way like this codegloupygloup wrote:Just for information i have tried the sceKernelAllocPartitionMemory like that :
when i run my code to the PSP i have black screen but when i comment data[0] = 0xFFFF; i have "TESTING" displayed correctlyCode: Select all
data = (int*)sceKernelAllocPartitionMemory(sizeof(int)*20); int i; data[0] = 0xFFFF; pgFillvram(0); while(1) { pgPrint4(1,1,0xFFFF,"TESTING"); pgScreenFlipV(); }
I have added this at the end of the startup.s :
Code: Select all
STUB_START "SysMemUserForUser",0x40000000,0x00030005 STUB_FUNC 0x237DBD4F,sceKernelAllocPartitionMemory STUB_FUNC 0xB6D61D02,sceKernelFreePartitionMemory STUB_FUNC 0x9D9A5BA1,sceKernelGetBlockHeadAddr STUB_END
Code: Select all
int sceKernelAllocPartitionMemory(void* buf,int size);
void sceKernelFreePartitionMemory(void* buf);
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.subbie wrote:Thats all fine for a temp fix but a form of mallocing will be needed.ooPo wrote: Why not just statically declare the memory?
int data[1024];
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?
You have no excuse to whine about this. Go forth and code, or wait for deliverance. :)
-
- Posts: 9
- Joined: Thu May 12, 2005 3:28 am