为什么 wxTextCtrl 显示文本的速度这么慢?
我有一个 wxTextCtrl,我需要在其中放入一个非常大的字符串。 (就像一个 15 MB 的字符串)唯一的问题是它非常慢。这就是我正在做的事情:
char * buff = ...
wxString data(buff, wxConvUTF8);
text->ChangeValue(data);
但是,这不是瓶颈。一旦该代码块所在的函数返回,就会发生这种情况。整个应用程序冻结约 30 秒。我在 ChangeValue 之后尝试了 wxYield ,这导致字符串的前几行显示在控件中,但之后它仍然冻结。我怎样才能避免这种情况?
我必须强调 ChangeValue 几乎立即返回。延迟发生在这之后,可能是在 wxTextCtrl 的内部消息处理程序或其他地方。
I have a wxTextCtrl and I need to put a very large string into it. (Like a 15 MB string) The only problem is it's very slow. Here is what I'm doing:
char * buff = ...
wxString data(buff, wxConvUTF8);
text->ChangeValue(data);
However, this is not the bottleneck. That occurrs as soon as the function this block of code is in returns. The whole app freezes for about 30 seconds. I tried wxYield right after ChangeValue and that causes the first few lines of the string to be displayed in the control but it still freezes after. How can I avoid this?
I must stress that ChangeValue returns almost instantaneously. The delay happens after this, probably in wxTextCtrl's internal message handlers or something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
wxTextCtrl
仅包装操作系统的标准文本控件,因此它的任何限制对于wxTextCtrl
也将是显而易见的。您可以做的是使用wxStyledTextCtrl
来代替,它能够加载数兆字节的文本并且不需要很长时间。您甚至可以通过设置日志的样式来突出显示日志的某些部分(例如读取中的错误消息),但这可能会再次增加加载时间。wxTextCtrl
wraps the standard text control of the OS only, so any limits this has will be apparent withwxTextCtrl
as well. What you can do is to use thewxStyledTextCtrl
instead, which is able to load multi-megabyte texts and doesn't take long to do it. You could even highlight portions of your log by styling them (for example error messages in read), but that would probably increase loading time again.