Killrazor
Killrazor

Reputation: 7176

Fast file writing in C++

I'm working in a system that use PHYSFS to search files. The problem is that now I need to deploy files (that is, to copy a phisical copy of the file into a directory). My first solution is open file, load into memory and then write to another file, but I think that it would exists a faster method to deploy files.

Any ideas?

Upvotes: 1

Views: 669

Answers (2)

bdonlan
bdonlan

Reputation: 231063

In general, yes, going through each file, reading it and then writing it is what you want. Note that you probably shouldn't load the entire file into memory at once, though - instead use PHYSFS_read to read a fixed buffer (64kb or so should be good) from the source file, write it to the destination file, and repeat.

Upvotes: 3

littleadv
littleadv

Reputation: 20262

Faster solution would be creating a hard link to an existing file (if you're not copying from a different system), but I'm not sure if that's what you're looking for.

If you need to create an actual physical copy - I don't think you can work around actually copying, and the way you suggested is the most efficient.

Upvotes: 1

Related Questions