【发布时间】:2018-01-12 11:41:54
【问题描述】:
在 x86 上,可能无法在工作线程上初始化 QImage。 (在 x64 中很少见)
当在 CPU 的核心数量上执行并行处理时,概率会增加。
这不仅可以通过从图像文件中读取,还可以通过指定其大小来初始化普通 QImage,或者只需调用 QImage::copy()。
这是避免它的代码。当然它并不完美。 请告诉我一个更好的方法。
QImage createImageAsync(QString path)
{
QImageReader reader(path);
if(!reader.canRead())
return QImage();
// QImage processing sometimes fails
QImage src;
int count = 0;
do {
src = reader.read();
if(!src.isNull())
break;
if(src.isNull() && count++ < 1000) {
QThread::currentThread()->usleep(1000);
continue;
}
return QImage();
} while(1);
return src;
}
【问题讨论】:
-
你想知道你的程序使用了多少内存吗?在 32 位 Windows 系统上,每个进程都有 2GB 的限制。另外,你确定是 malloc 失败了吗?如果是的话,你是怎么发现的。您有任何错误消息吗?
-
出现输出“QImage:内存不足,返回空图像”。检查QImage的实现,我发现根本原因是由于malloc失败。内存使用量约为 600 MB(私有工作集)。
-
您的计算机是否有足够的可用内存?您是如何测量已用内存的?
-
我的电脑是 Windows 7 x64 并且有 16GB 内存。
标签: qt malloc heap-memory qthread qtconcurrent