将数据并行写入磁盘? [英] Writing data to disk in parallel?
问题描述
所以我正在开发一个C ++ / cli图像处理库,我试图优化我的代码。基本上,我通过了一个System :: Drawing :: Bitmap的图像,然后我需要写到磁盘,执行复杂的分析,并返回分析的结果。我想我可以将图像并行写入磁盘以加速事情(我的算法不会修改图像)。但是,我没有很多工作,所以我想得到你的投入,最好的方法是这样做。
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!
推荐答案
并行写入/读取单个机械磁盘不是一个好的因为机械头需要每次旋转以服务I / O请求,因此使用多个线程将只是不必要地反弹它并创建开销。
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.
这篇关于将数据并行写入磁盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!