c++ - How propertly clear file in linux -


Good day, I open the file to write some content to it. Code below:

  class file_worker {public: file_worker (const std :: string and path): path_ (path), stop_ (false) {umask (0); File_descriptor_ = open (path_.c_str (), O_WRONLY | O_CREAT, 0666); } Zero operator () () {if (file_descriptor _! = - 1) {clear_file (); // write something}} zero clear_file () {} ~ file_worker () {if (file_descriptor _! = - 1) {close (file_descriptor_); }} Private: const std :: string path_; Int file_descriptor_; Bull stop_; };   

How to apply clear_file (); Is it possible to clear the file descriptor without closing the function? What is the fast way to write files? Is it possible to file some threads together in different parts of the file? (May be the use of Lseek)?

You did not define what it meant to clear a file.

You use the file to minimize it in size 0.

You can zero all the bytes in the file. Then, use with writing (2) or maybe

if another process is writing the file at the same time (which is poor practice).

I'm not sure that by using multi-threading all the bytes have to be zero. (Doing this is disk-intensive unless system file cache is killed, and multi-threading will not accelerate the disc), so I'll be the first benchmark.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -