将数据并行写入磁盘?

Ami*_*mil 3 multithreading c++-cli image-processing

所以我正在研究C++/cli图像处理库,并试图优化我的代码.基本上,我传递了一个System :: Drawing :: Bitmap的图像,然后我需要写入磁盘,执行复杂的分析,并返回分析结果.我以为我可以将图像并行写入磁盘以加快速度(我的算法不会修改图像).但是,我没有使用过很多线程,所以我想知道最好的方法是什么.

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;
}
Run Code Online (Sandbox Code Playgroud)

请让我知道你的想法.先感谢您!

Tud*_*dor 6

从单个机械磁盘并行写入/读取并不是一个好主意,因为机械磁头每次都需要旋转来处理I/O请求,因此使用多个线程只会不必要地反弹并产生开销.

您可以尝试进行基准测试,但我担心您只需要使用单个线程并按顺序编写.