So I have tried:
int buff_length = 8192;
ifstream stream;
char* buffer = new char[buff_length];
stream.open( path.string().c_str(), ios::binary );
boost::system::error_code ignored_error;
while (stream)
{
stream.read(buffer, buff_length);
boost::asio::write(*socket, boost::asio::buffer(buffer, stream.gcount()),
boost::asio::transfer_all(), ignored_error);
}
I wonder how you do it - how to do it faster?
My app shall work across Windows, linux and mac os. That is why I use boost alot. I use ab
for testing. I want to get 2 or at least 1.5 times faster on reading and sending files. May be Boost::Iostream can help me any how?
Not entirely sure what you're after, but to answer your question about fast reading of files you can map the file into memory.
This way you read from the memory instead of from disk. Depending on the file size and such there are different approaches that might be interesting, e.g. map whole file if small or map regions of file throughout the file as you process it if it's a large file.
In Boost.Interprocess you can read more about this here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With