gpt4 book ai didi

multithreading - 将数据并行写入磁盘?

转载 作者:行者123 更新时间:2023-12-03 12:44:03 25 4
gpt4 key购买 nike

所以我正在研究 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;
}

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

最佳答案

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

您可以尝试进行一些基准测试,但恐怕您只能求助于使用单个线程并按顺序编写。

关于multithreading - 将数据并行写入磁盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10254147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com