It it somehow possible to draw a string using the GDI onto an image using a StringBuilder instead of a string? There is no Graphics.DrawString() overload that accepts a StringBuilder. But a regular string can in some cases dramatically increase the GC time (in my case 52% according to the CLR Profiler).
Note: I DON’T want to use the XNA Framework which supports StringBuilders as of 4.0.
I don’t believe it is possible without using some alternative graphics library.
Since .NET 4.0,
StringBuilderdoes not use aStringclass internally (even with reflection you cannot extract aStringobject).You are right that calling
myStringBuilder.ToString()will incur a performance hit; it is essentially making a copy of your string each time it is called. But in code that callsGraphics.DrawString(), I just don’t see that being a bottleneck.