Is there a more efficient text spooler than TextWriter / StringBuilder

For a situation such as capturing text in stages, for example, if you received all calls to output.write when the page was rendering, and they were added to the text editor on top of the string constructor.

Is there a more efficient way to do this? Is something that exists in dotnet already desirable? Especially if their total size is more than one hundred kilos. Maybe something more like an array of pages, rather than continuous memory?

+4
source share
3 answers

I think StringBuilder is the most efficient way to add text to .net. To be more efficient, you can specify the initial size of the StringBuilder when creating it.

+3
source

It depends on what you do with this text.

If the problem is with tracking or logging, I would say that it is best to use ETW (Event Tracing for Windows). This is a kernel level tracking tool that was built into Windows with Windows 2000, and it is much faster than doing I / O.

If you are not using .NET 2.0, you need to do a little Win32 API work to use it, and you need to create a provider class that you register with the system. It's a little complicated, but worth the effort.

If you are using .NET 3.5, the Etw managed classes can be found in System.Diagnostics.Eventing.

+3
source

This is as good as it gets. You can use StringWriter, but it is still written to StringBuilder

+1
source

Source: https://habr.com/ru/post/1276796/


All Articles