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 

Optimizing a copy funct

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



Joined: 21 Feb 2008
Posts: 386

PostPosted: Tue Jun 03, 2008 6:47 am    Post subject: Optimizing a copy funct Reply with quote

Hi,
I would have to optimize this function, but I don't know whether to do...
I've increased the buffer and free it at the end, it works very good and fast, but (I think) the best buffer depends on the file size, right?
Code:

int fileCopy(char* inSrc , char* inDest)
{
     SceUID tempSrc = sceIoOpen(inSrc, PSP_O_RDONLY, 0777);
     if(!tempSrc){
            return -1; // Error while reading file...
     }
     SceUID tempDest = sceIoOpen(inDest, PSP_O_WRONLY | PSP_O_CREAT, 0777);
     if(!tempDest) {
          sceIoClose(tempSrc);
          return -2; // Error while writing file...
     }
     char* tempData;
     tempData=(char*)malloc(1024*1024);
     int tempRead = sceIoRead(tempSrc, tempData, 1024*1024);
     int tempWritten;
     while(tempRead > 0){
                    tempWritten = sceIoWrite(tempDest, tempData, tempRead);
                    tempRead = sceIoRead(tempSrc, tempData, 1024*1024);
     }
     sceIoClose(tempDest);
     sceIoClose(tempSrc);
     free(tempData);
     return 0;
}

Can anyone give me a little help?
_________________
Get Xplora!
Back to top
View user's profile Send private message
cyberfish



Joined: 19 May 2008
Posts: 19

PostPosted: Tue Jun 03, 2008 5:44 pm    Post subject: Reply with quote

I don't think it would really be dependent on the file size.

Try several buffer sizes and benchmark them =).

*edit*
BTW, why is everything named temp?... The function has its own scope that is isolated from the global namespace, so you don't need to try to protect the global namespace.
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Wed Jun 04, 2008 12:00 am    Post subject: Reply with quote

ok, I've resolved!
_________________
Get Xplora!
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