Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
797 views
in Technique[技术] by (71.8m points)

multithreading - Writing data to disk in parallel?

So I am working on a C++/cli image processing library and am trying to optimize my code. Basically, I am passed a System::Drawing::Bitmap of the image, which I then need to write to disk, perform complex analysis on, and return the results of the analysis. I thought that I could write the image to disk in parallel to speed up things (my algorithm does not modify the image). However, I have not worked with threads much, so I wanted to get your input on what the best way to do this would be.

string ProcessImage(System::Drawing::Bitmap ^bmp, System::String^ targetFile)
{
    bmp->Save(targetFile);
    System::Drawing::Bitmap^ bmp8 = BitmapConvertPixelFormat(bmp, 8); //<-- a function I wrote which converts the 32bpp I am passed into an 8bpp one
    string results = Analyze(bmp8); //<--- takes a good bit of time
    return results;
}

Please let me know your thoughts. Thank you in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Writing/reading in parallel to/from a single mechanical disk is not a good idea because the mechanical head needs to spin every time to service an I/O request, so using multiple threads will just bounce it around needlessly and create overhead.

You can try to benchmark a bit, but I'm afraid you'll just have to resort to using a single thread and writing sequentially.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...