Open GWRon opened 3 years ago
What would that achieve?
An object less which is just created "temporarily"
As said you might have a function in which you concatenate a string and return it. In this function you most probably do Local sb:TStringBuilder = new TStringBuilder
.
But I understand that a struct + wrapper would mean a lot of boilerplate code ...
The whole point of a builder is being able to grow, so it needs to allocate heap memory. Turning a builder into a struct won't get rid of that. You'd save one single object allocation and end up with an "object" whose memory you need to destroy manually - which is what BlitzMax deliberately wants to avoid by having a garbage collector. You may as well call the underlying C function directly, but I don't really see why you'd want to do that tbh.
Nonetheless it should be an object less..if only used as one shot builder in a function.
Surely too much efforts required (duplicate code) to make it a struct and a type (SStringBuilder and TStringBuilder).
Using the underlaying C stuff...would fight the approach of Blitzmax...a bit at least
For now TStringBuilder is an object - but often you might just use it to have a "lightweight" string concatenation.
Maybe it would be useful to have it as a struct too?