Reporting transfer datarate to an UI
<p>I have a Visual Studio 2008 C++ application where I'm copying data from a remote file <code>ifstream</code> to a local file <code>ofstream</code>. The transfer code looks basically like this:</p>

<pre><code>void MyTransferThread()
{
    std::ofstream local_file( /*...*/ );
    std::ifstream remote_file( /*...*/ );

    // an arbitrary block size
    const size_t buffer_size = 4096; 
    char buffer[ buffer_size ];

    while( remote_file )
    {
        remote_file.read( buffer, buffer_size );
        int read = remote_file.gcount();
        local_file.write( buffer, read );
    }
}
</code></pre>

<p>What's the best way to report the current rate of the transfer (in bytes/second) to a separate UI thread while having a minimal effect on the transfer speed?</p>
