我正在将大量格式化文本的日志写入 .net windows 窗体应用程序中的文本框.
I am writing a log of lots and lots of formatted text to a textbox in a .net windows form app.
一旦数据超过几兆,它就会变慢.由于我要附加字符串,因此每次都必须重新分配对吗?我只需要将值设置为文本框一次,但在我的代码中我正在执行 line+=data
数万次.
It is slow once the data gets over a few megs. Since I am appending the string has to be reallocated every time right? I only need to set the value to the text box once, but in my code I am doing line+=data
tens of thousands of times.
有没有更快的方法来做到这一点?也许不同的控制?有没有可以使用的链表字符串类型?
Is there a faster way to do this? Maybe a different control? Is there a linked list string type I can use?
如果文本框以增量方式添加,例如日志输出,StringBuilder 将无济于事.
StringBuilder will not help if the text box is added to incrementally, like log output for example.
但是,如果上述情况属实,并且如果您的更新足够频繁,则您可能应该缓存一些更新,然后一步添加它们(而不是不断地添加).这将为您节省许多字符串重新分配......然后 StringBuilder 会很有帮助.
But, if the above is true and if your updates are frequent enough it may behoove you to cache some number of updates and then append them in one step (rather than appending constantly). That would save you many string reallocations... and then StringBuilder would be helpful.
注意事项:
这篇关于将大量文本写入文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!