Re: Gtk::Main::iteration();



Dear Adam!

I have this code:
for (long long i = 0; i < FileSize; i++)
{
   if(Gtk::Main::events_pending())
       Gtk::Main::iteration();

   fputc(_char[0], File);
}
But it is very slow. How Can speed up him?

It looks as if you were writing 'FileSize' copies of the character '_char[0]' to 'File'. And you don't want your windows to stop responding, so you are giving them a prod after every byte.

You don't really want to start from here.

(1) Writing a file byte by byte is unneccessarily slow, even without calls to Gtk::Main::events_pending() inside the loop.

(2) Any single call to fputc() can block. For instance 'File' might be on a remote filesystem and the connection might be bad or down. Your windows will then stop responding, although that was what you were trying to avoid.

(3) A call to Gtk::Main::iteration() can probably lead to other parts of your program being executed. If you are not absolutely sure what you are doing, you will shoot yourself in the foot.

The file operation should be in a seperate thread. And instead of hand-coding that, you might want to use the class Gio::File from glibmm. It has *async* functions one of which might suit your needs.

Hope this helps,
Mark


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]