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 

malloc newbie question

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



Joined: 12 May 2005
Posts: 9

PostPosted: Thu May 12, 2005 3:34 am    Post subject: malloc newbie question Reply with quote

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
View user's profile Send private message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu May 12, 2005 3:37 am    Post subject: Reply with quote

Try including malloc.h:

http://cvs.ps2dev.org/cgi-bin/viewcvs.cgi/ps2sdk/ee/libc/include/malloc.h?rev=1.5

The function itself would be in the libc library, so make sure you have a -lc on your link line.
Back to top
View user's profile Send private message Visit poster's website
gloupygloup



Joined: 12 May 2005
Posts: 9

PostPosted: Thu May 12, 2005 3:43 am    Post subject: Reply with quote

Thanks, of course i have added the malloc.h ;-) but not the -lc
im going to test that right away.

Thanks !
Back to top
View user's profile Send private message
Orion_



Joined: 27 Jan 2005
Posts: 69

PostPosted: Thu May 12, 2005 3:49 am    Post subject: Reply with quote

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
View user's profile Send private message
gloupygloup



Joined: 12 May 2005
Posts: 9

PostPosted: Thu May 12, 2005 3:52 am    Post subject: Reply with quote

Orion_ : i have checked your plasma wich work fine dont you alloc anything in memory ?
Back to top
View user's profile Send private message
Orion_



Joined: 27 Jan 2005
Posts: 69

PostPosted: Thu May 12, 2005 3:54 am    Post subject: Reply with quote

no :/
I compute the plasma picture in realtime inside the vram directly.
Back to top
View user's profile Send private message
gloupygloup



Joined: 12 May 2005
Posts: 9

PostPosted: Thu May 12, 2005 3:58 am    Post subject: Reply with quote

hmm ok , i m going to do something about that so.
Back to top
View user's profile Send private message
Klesk



Joined: 02 Apr 2005
Posts: 4

PostPosted: Thu May 12, 2005 4:05 am    Post subject: Reply with quote

i suppose the guy who made the gameboy emulator knows how to allocate memory
Back to top
View user's profile Send private message
sq377



Joined: 11 Apr 2005
Posts: 87

PostPosted: Thu May 12, 2005 4:19 am    Post subject: Reply with quote

yea but he also doesn't know english very well.
Back to top
View user's profile Send private message AIM Address MSN Messenger
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu May 12, 2005 4:32 am    Post subject: Reply with quote

Oops, I thought this was a PS2-related question. Sorry. :)

Why not just statically declare the memory?

int data[1024];
Back to top
View user's profile Send private message Visit poster's website
subbie



Joined: 05 May 2005
Posts: 122

PostPosted: Thu May 12, 2005 4:51 am    Post subject: Reply with quote

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
View user's profile Send private message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu May 12, 2005 5:00 am    Post subject: Reply with quote

It may be a little early in the life of the pspdev world to demand things like malloc.
Back to top
View user's profile Send private message Visit poster's website
subbie



Joined: 05 May 2005
Posts: 122

PostPosted: Thu May 12, 2005 5:21 am    Post subject: Reply with quote

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
View user's profile Send private message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu May 12, 2005 5:27 am    Post subject: Reply with quote

You bring a tear to my eye with such lovely words. :)
Back to top
View user's profile Send private message Visit poster's website
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Thu May 12, 2005 6:02 am    Post subject: Reply with quote

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
View user's profile Send private message
gloupygloup



Joined: 12 May 2005
Posts: 9

PostPosted: Thu May 12, 2005 7:07 am    Post subject: Reply with quote

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
View user's profile Send private message
gloupygloup



Joined: 12 May 2005
Posts: 9

PostPosted: Thu May 12, 2005 7:31 am    Post subject: Reply with quote

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
View user's profile Send private message
gloupygloup



Joined: 12 May 2005
Posts: 9

PostPosted: Thu May 12, 2005 7:40 am    Post subject: Reply with quote

Edit : post deleted ( wrong manipulation = double post )
Back to top
View user's profile Send private message
Shito



Joined: 11 May 2005
Posts: 21

PostPosted: Thu May 12, 2005 8:04 am    Post subject: Reply with quote

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
View user's profile Send private message
gloupygloup



Joined: 12 May 2005
Posts: 9

PostPosted: Thu May 12, 2005 8:08 am    Post subject: Reply with quote

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
View user's profile Send private message
tonymoon



Joined: 10 May 2005
Posts: 4

PostPosted: Thu May 12, 2005 12:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
Guest






PostPosted: Thu May 12, 2005 3:48 pm    Post subject: Reply with quote

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

PostPosted: Thu May 12, 2005 6:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
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