简体   繁体   English

是否有比TextWriter / StringBuilder更高效的文本假脱机程序

[英]Is there a more efficient text spooler than TextWriter/StringBuilder

For a situation like capturing text incrementally, for example if you were receiving all of the output.write calls when a page was rendering, and those were being appended into a textwriter over a stringbuilder. 对于以增量方式捕获文本的情况,例如,如果在页面呈现时接收到所有output.write调用,并且这些调用是通过stringbuilder附加到文本编写器中的。

Is there a more efficient way to do this? 有没有更有效的方法来做到这一点? Something that exists in dotnet already preferably? dotnet中存在的东西已经优先了吗? Especially if there's a total size over a hundred k. 特别是如果总大小超过一百k。 Maybe something more like an array of pages rather than contiguous memory? 也许更像是一系列页面而不是连续的内存?

It depends on what you're doing with that text. 这取决于你对该文本的处理方式。

If the concern is tracing or logging, I'd say your best bet is to use ETW (Event Tracing for Windows). 如果问题是跟踪或记录,我会说你最好的选择是使用ETW(Windows事件跟踪)。 It's a kernel-level tracing facility that's been built into Windows since Windows 2000 and it's much, much faster than doing file I/O. 它是一个内核级跟踪工具,自Windows 2000以来一直内置在Windows中,它比文件I / O快得多。

If you're not using .NET 2.0, you have to do a little win32 API work to use it, and you have to create a provider class that you register on the system. 如果您不使用.NET 2.0,则必须执行一些win32 API工作才能使用它,并且您必须创建在系统上注册的提供程序类。 It's a little complicated but worth the effort. 这有点复杂但值得付出努力。

If you're using .NET 3.5, the managed Etw classes can be found in System.Diagnostics.Eventing. 如果您使用的是.NET 3.5,则可以在System.Diagnostics.Eventing中找到托管的Etw类。

I think StringBuilder is the most efficient way to append text in .net. 我认为StringBuilder是在.net中追加文本的最有效方式。 To be more efficient you can specify the initial size of the StringBuilder when you create it. 为了提高效率,您可以在创建StringBuilder时指定它的初始大小。

That's as good as it gets. 这就是它的好处。 You can use a StringWriter but it's still writing into a StringBuilder 您可以使用StringWriter,但它仍然写入StringBuilder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM