2

我正在使用 wxWidgets 和 Visual C++ 创建类似于在 GUI 中使用具有丰富格式(颜色、字体、图像)的 Unix“tail -f”的功能。我的目标是 wxMSW 和 wxMAC。

显而易见的答案是使用 wxTextCtrl 和 wxTE_RICH,调用 wxTextCtrl::SetDefaultStyle() 和 wxTextCtrl::WriteText()。

但是,在我的 3ghz 工作站上,以发布模式编译,我无法继续跟踪平均每行增长 1 毫秒的日志,最终落后。对于每一行,我都会招致:

  1. 两次调用 SetDefaultStyle()
  2. 两次调用两次 WriteText()
  3. 调用 Freeze() 和 Thaw() 小部件

运行此程序时,在填充了大约 20,000 行之后,我的 CPU 使用 wxMSW 在一个内核上达到 100%。一旦达到某个阈值,程序就会明显变慢,进一步落后。

我愿意使用其他控件(wxListCtrl、wxRichTextCtrl 等)。

4

3 回答 3

1

您是否考虑过限制视图中的行数?当我们遇到类似问题时,我们只是确保视图中的行数不超过 10,000 行。如果底部有更多行,我们将删除顶部的行。这不是使用 WxWidgets,而是在 Mac 上使用本机 Cocoa UI,但问题是一样的。如果样式化的文本视图(带有颜色、格式和漂亮的打印)变大,在底部添加更多数据会变得非常慢。

于 2008-09-29T14:38:01.950 回答
0

听起来您正在使用的控件根本不是针对您投入的数据量而构建的。我会考虑构建一个自定义控件。以下是您可以考虑的一些事项:

  1. 当有新行进入时,您不需要重新渲染以前的行......它们不会改变,布局也不会因为新数据而改变。
  2. 尝试一次只在内存中保留可见部分和几个回顾屏幕。这会使它更轻一些......但是如果您希望用户能够比您的回看更远地向后滚动并使一切看起来是无缝的,那么您将必须进行自己的滚动管理。
  3. Don't necessarily update one line at a time. When there is new data, grab it all and update. If you get 10 lines really quickly, and you update the screen all at once, you might save on some of the overhead of doing it line by line.

Hope this helps.

于 2008-10-02T15:37:06.887 回答
0

Derive from wxVListBox. From the docs:

wxVListBox is a listbox-like control with the following two main differences from a regular listbox: it can have an arbitrarily huge number of items because it doesn't store them itself but uses OnDrawItem() callback to draw them (so it is a Virtual listbox) and its items can have variable height as determined by OnMeasureItem() (so it is also a listbox with the lines of Variable height).

于 2009-10-24T06:27:38.323 回答