It is 2019 and we have a banking project which uses mainframe as data store and transactions.
We are using DTO's (Commarea, plain c# class) that is converted to plain string (this is how mainframe works) then sent to Mainframe.
While converting a class to string representation we use several string operations such as substring, pad left, pad right, trim etc.
As you can imagine, this causes several string allocations and hence garbage collection. It is usually at generation 0 but still.
Especially types like Decimal
which is a Pack type
in mainframe that fits into 8 bytes creates several strings.
I tried using ReadonlySpan<char>
for example for substring. See example.
However, there are operations like PadRight
, PadLeft
which is not avaiable, because it is a read only span.
Update: To clarify a part of conversion happens as follows:
val.Trim().Substring(5).PadRight(10);
I know that this creates 3 string. I know strings are immutable. My question is about doing the above operation with ReadonlySpan
or Memory
.
I can not use ReadonlySpan only for substring because as soon as I call ToString
method I m losing the benefits.
I have to call ToString
all the way at the end.
Is there another construct that supports other operations behind substring, that I can actually add remove data to the memory?
Thanks.