No Garbage StringBuilder Wrapper class

Ah success i think ok i think i’ve got a working No Garbage StringBuilder class made.
I been tinkering with this on and off its looking pretty good
the basic appends all seem to be working.
I even got a AppendAt in there.

well i don’t think i can get these operators to work though i gave up on that part unless someone else knows how to chain value types to the wrapper and the stringbuilders.
I was shooting for something like
sbm += some_int + some_stringbuilder + 8f; ect… but couldn’t get it to work.


framerate test with gc shown set the bool to use stringbuilder or not to see the difference

no garbage stringbuilder wrapper

the entire opengl project

I let it run for 3 minutes and did not see monogame generate any garbage at all, other then the initial start up allocations i saw no other allocations.

So basically now the framerate counter can also let you spot any code you run that generates garbage without having to guessing when there is a hiccup or keep profiling it when nothings wrong yet .

Garbage free is always a good thing. Well done.

I renamed the class to Text.

Well it sure isn’t done yet. If anyone’s good with operators and want to post up some fixes go for it.
The float decimal on the line that sets the decimal its supposed to be
if n > float.minvalue not 0 that was a copy paste bug. I forgot to check Insert so im sure it generates trash.

Garbage wise, It works fine it you use it like in the example class.
Though im having a hell of a time making sure it works right with operator overloading.
Im not very good at it, in fact im pretty noob at it.
I want it to work like a regular string without garbage.

I really really want to be able to do calls like following and still not generate garbage.

SomeCall( a + b + c );

I can do the assignment calls
Text n = a + b +c;

But if its in some method i cant figure out how to do it with the operators without generating a ton of garbage,
trying to figure out a logical pattern to zero out the length of a temporary internal stringbuilder at the time of the actual equals or += assignment.
Zeroing out the temp length after the assignment occurs but it gets tricky.
Its fregging complicated im not sure what gets called when.
If i do something like this M( c + ( a + b)); i have the chain running down a temp stringbuilder thats fine if it is a sb call, but if its a text call, then it wants to make a new Text object via the constructor i think then pass the value of the reference, which will go out of scope in the method on return and have to get collected.

so i end up with something like this

txt_msg.Length = 0;
ww2s.DrawWithMsg(1, c2, false, txt_msg);

if i do this instead

ww2s.DrawWithMsg(1, c2, false, msg + txt_worldtoscreen);

can get it to do it without making a ton of garbage;

been at it all day arrrrrrggggggggggg.

In case anyone comes across this in the future.

This will be maintained on github here…