PDA

View Full Version : copies file doesn't work well



dreamer
10th May 2008, 21:29
HI.
I have to copy a file, from a directory to another(changing the name).

I use the static function


QFile::copy(source,dest)


...but, often, it doesn't make the copy(it makes the copy very late). I also remove the dest file, if one with that name exists and use the flush() function to write the buffered data.

How can i obtain a fast written on the filesystem???
I use linux with ext3.

wysota
10th May 2008, 21:43
QFile::copy() performs the copy in userspace, which is slow. If you are after speed, it's best to use dedicated methods. Linux has a very fast function for it called sendfile(). It is very efficient, but highly unportable - available only in Linux (other Unices might have it but with different semantics).

dreamer
10th May 2008, 21:48
i 'd like to have a portable solution.
Why the flush() function doesn't work?

wysota
10th May 2008, 22:00
What would you like it to do? It won't speed up anything.

As for portability, I suggest using #ifdef directives and use sendfile() on Linux, some native function on Windows and QFile::copy() elsewhere.