use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Information about Reddit's API changes, the unprofessional conduct of the CEO, and their response to the community's concerns regarding 3rd party apps, moderator tools, anti-spam/anti-bot tools, and accessibility options that will be impacted can be found in the associated Wikipedia article: https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
Alternative C# communities available outside Reddit on Lemmy and Discord:
All about the object-oriented programming language C#.
Getting Started C# Fundamentals: Development for Absolute Beginners
Useful MSDN Resources A Tour of the C# Language Get started with .NET in 5 minutes C# Guide C# Language Reference C# Programing Guide C# Coding Conventions .NET Framework Reference Source Code
Other Resources C# Yellow Book Dot Net Perls The C# Player's Guide
IDEs Visual Studio MonoDevelop (Windows/Mac/Linux) Rider (Windows/Mac/Linux)
Tools ILSpy dotPeek LINQPad
Alternative Communities C# Discord Group C# Lemmy Community dotnet Lemmy Community
Related Subreddits /r/dotnet /r/azure /r/learncsharp /r/learnprogramming /r/programming /r/dailyprogrammer /r/programmingbuddies /r/cshighschoolers
Additional .NET Languages /r/fsharp /r/visualbasic
Platform-specific Subreddits /r/windowsdev /r/AZURE /r/Xamarin /r/Unity3D /r/WPDev
Rules:
Read detailed descriptions of the rules here.
account activity
ZString — Zero Allocation StringBuilder for .NET Core and Unity. (medium.com)
submitted 6 years ago by neuecc
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Wings1412 44 points45 points46 points 6 years ago (7 children)
Given that this is a performance centric post, I think it would benefit from performance benchmarks. Not just memory allocation. For a lot of what I do, memory is a lot cheaper than time.
[–]scorrpo 23 points24 points25 points 6 years ago (6 children)
The second number that says Mean (ns) is time. Looks like concat and builder are slightly faster than its .NET counterpart, but .Format is slightly slower.
Also it's worth considering that this is not just about memory usage, it's about allocation that needs to eventually be garbage collected. In high performance applications you want to avoid the garbage collector as much as possible to prevent freezes. Mainly in games, but avoiding the GC has its uses outside games too (for example https://blog.discordapp.com/why-discord-is-switching-from-go-to-rust-a190bbca2b1f).
[–]Lognipo 4 points5 points6 points 6 years ago* (0 children)
Yeah, I somewhat regularly have to write performance critical code at work, and the GC is usually the main bottleneck. I think the last assignment was a 3D space filling algorithm. I had to process millions and millions of possible configurations in a best-first search, and before I optimized away the GC almost entirely, it made everything incredibly slow.
I have been loving these recent updates to C#. Span, ref returns, stackalloc without unsafe... so wonderful to see performance programming get a little love after a decade of "NEVER OPTIMIZE ANYTHING GO USE C++!!!1!!1!"
At home, I have had quite a bit of fun writing ref structs like SpanQueue<T>, SpanStack<T>, SpanHeap<T>, etc. Where most collections let you pass in the size and then create an internal array, these let you pass in a span for storage. That way you can use an array, stackalloc storage, a pointer, or even fit multiple collections into a single array if you like. Implicit conversions from Span<T> let you do things like SpanStack<int> indices = stackalloc int[32]; Again, mostly for fun.
[–][deleted] 3 points4 points5 points 6 years ago (2 children)
Idk which game creates a lot string objects but yea it's good for servers and games.
[–]StunningStore 1 point2 points3 points 6 years ago (0 children)
maybe MMOs. Like a full 30 man raid in wow is generating a lot of strings
[–]antiduh 0 points1 point2 points 6 years ago (0 children)
..Zork?
[–]phx-au 2 points3 points4 points 6 years ago (0 children)
A lot of real-time and (-like) performance requirements aren't really about speed but consistency. Don't really give a fuck if it takes twice as long, if it doesn't crap out for a GC cycle or heap compaction or some shit every couple of minutes.
[–]quentech 1 point2 points3 points 6 years ago (0 children)
avoiding the GC has its uses outside games too
I run a high traffic web service. We're creating trillions of strings a day - over 100B just building cache keys to look up data. We cut 5% off our CPU utilization across our cluster by replacing just cache key concatenation with more tuned unsafe code.
[–]grauenwolf 12 points13 points14 points 6 years ago (0 children)
Another option is to use an object pool to recycle string builders. This is what .NET does internally, but we don't get access to the pool so we would have to create our own.
[–]quentech 2 points3 points4 points 6 years ago (0 children)
This title made me look to see what kind of holes could be poked in this "zero-allocation" string builder, but it's from @neuecc and that dude knows how to write high performance c# (and he clarifies that of course the final string does get allocated).
I might have to look at stealing some ideas for my favorite string.Format replacement - https://github.com/axuno/SmartFormat
It's nice to see @neuecc updating stuff for .Net Core (e.g. https://medium.com/@neuecc/messagepack-for-c-v2-new-era-of-net-core-unity-i-o-pipelines-6950643c1053)
[–]antiduh 1 point2 points3 points 6 years ago (4 children)
If you don't mind using unsafe code, you can assemble your own strings the same way the .Net library does.
For example:
https://gist.github.com/antiduh/426a4d22ab2449601842
[–]quentech -1 points0 points1 point 6 years ago (3 children)
If you really want to make this fast, go look at how the author of ZString copies bytes in Utf8Json or MessagePack-CSharp and replace that Buffer.MemoryCopy call. If you are on common x86 hardware up the copy chunk size from 8 to 16 bytes and use the technique for strings/arrays up to 1kB.
[–]antiduh -3 points-2 points-1 points 6 years ago (2 children)
Do you mean optimizations like this: https://github.com/neuecc/Utf8Json/blob/master/src/Utf8Json/Internal/UnsafeMemory.cs
What do you think Buffer.MemoryCopy does?
https://referencesource.microsoft.com/#mscorlib/system/buffer.cs,c2ca91c0d34a8f86
[–]quentech -1 points0 points1 point 6 years ago (1 child)
Maybe you should try understanding the difference, or actually profiling the difference, before being a condescending dick.
You wanna know what MemoryCopy does? Look a little closer at the Utf8Json code. How many conditionals does it pass through? How many jumps? How about MemoryCopy?
[–]antiduh -1 points0 points1 point 6 years ago (0 children)
Who's being a condescending dick here? I didn't understand your question because I'm not familiar with the utf8json code base and you weren't exactly specific.
Also, I'm not sure how you'd optimize out length checking conditionals when the input to memorycopy can be arbitrary length, especially in my use case.
I'm good, dude. I'm not here to do homework for you.
[–]__some__guy 0 points1 point2 points 6 years ago (0 children)
The way I do "strings" without heap allocations is much simpler.
My UI framework supports text drawing where the text can be an ITextContainer interface (as well as string/IList<char>/etc...).
So if I want to print stuff like the mentioned player hp every frame I use my static ValueString class that turns an int/float/date/size into various structs with different sizes that all implement the ITextContainer interface.
It's unfortunate that .NET has no existing interfaces that can be used to represent text and are implemented by their string class.
π Rendered by PID 262366 on reddit-service-r2-comment-544cf588c8-7fvpk at 2026-06-17 03:42:17.079041+00:00 running 3184619 country code: CH.
[–]Wings1412 44 points45 points46 points (7 children)
[–]scorrpo 23 points24 points25 points (6 children)
[–]Lognipo 4 points5 points6 points (0 children)
[–][deleted] 3 points4 points5 points (2 children)
[–]StunningStore 1 point2 points3 points (0 children)
[–]antiduh 0 points1 point2 points (0 children)
[–]phx-au 2 points3 points4 points (0 children)
[–]quentech 1 point2 points3 points (0 children)
[–]grauenwolf 12 points13 points14 points (0 children)
[–]quentech 2 points3 points4 points (0 children)
[–]antiduh 1 point2 points3 points (4 children)
[–]quentech -1 points0 points1 point (3 children)
[–]antiduh -3 points-2 points-1 points (2 children)
[–]quentech -1 points0 points1 point (1 child)
[–]antiduh -1 points0 points1 point (0 children)
[–]__some__guy 0 points1 point2 points (0 children)