Optimizing a copy funct

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Optimizing a copy funct

Post by ne0h »

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: Select all

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?
cyberfish
Posts: 19
Joined: Mon May 19, 2008 3:39 pm

Post by cyberfish »

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.
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

ok, I've resolved!
Post Reply