我注意到我的 Qt 应用程序中存在大量页面错误。我通过调整停靠小部件(下方有数十个小部件的小部件树)的大小来重现它 2 秒,并使用 AQTime 跟踪该操作。我为此操作遇到了 2000 个页面错误。这是为什么?
在 Windows XP 32 位上使用 Qt 4.5.3
更新:它们是软页面错误
UPDATE2:我在 Qt Designer 中创建了一个 ui,其中包含 1 个组合框,其中包含 2 个项目。如果我预览此内容,每次单击组合框选择其中一项时都会出现 200 个页面错误。
Parents
Code Type Routine Name Faults Faults with Children Hit Count
x86 qt_memfill_template<unsigned int,unsigned int> 2416 2416 5160
x86 qt_memfill<unsigned int> 2416 2416 5160
x86 qt_rectfill<unsigned int> 0 2416 5160
x86 qt_rectfill_template<unsigned int> 0 2416 63
x86 qt_rectfill_quint32 3 2419 63
x86 fillRect_normalized 1 2420 63
x86 QRasterPaintEngine::fillRect 3 2423 63
x86 QRasterPaintEngine::fillRect 1 2424 63
x86 QPainter::fillRect 1 2427 63
x86 fillRegion 0 2427 15
x86 QWidgetPrivate::paintBackground 2 2430 12
x86 QWidgetPrivate::drawWidget 0 2430 12
x86 QWidgetBackingStore::sync 2 2596 12
x86 QWidgetPrivate::syncBackingStore 4 2610 12
x86 QETWidget::translateConfigEvent 0 2479 6
x86 QtWndProc 0 2495 12
最佳答案
最有可能的是,Qt 分配了一个新的位图来保存小部件的外观,并且系统通过为进程分配新的页面来满足这个请求。第一次写入这些页面时,会发生软页面错误,实际页面会映射到进程地址空间。这可以通过在重绘调用之间缓存位图来避免;但是,在调整大小时,所需位图的大小会发生变化,因此此优化不再适用;每次尺寸更改时,都必须重新分配位图(导致软页面错误)。
不过,这真的会对性能产生影响吗?
关于c++ - 呈现 QWidgets 时出现大量页面错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6442101/