I am working on high-performance code in which this design is part of a critical performance section.
This is what happens in some sections:
- A
string
"scanned", and metadata is stored efficiently. - Based on these fragments, the metadata of the main line is divided into
char[][]
. - That
char[][]
was transferred to string[]
.
Now I know that you can just call new string(char[])
, but then the result will need to be copied.
To avoid this redundant copy step, I think it should be possible to write directly to the string internal buffer. Despite the fact that it will be an unsafe operation (and I know that it brings a lot of consequences, such as overflow, forward compatibility).
I have seen several ways to achieve this, but none of them are satisfied.
Does anyone have any true suggestions on how to achieve this?
Additional Information:
The actual process does not include conversion to char[]
necessarily, it is practically an operation with several substrings. Like 3 pointers and their lengths added.
StringBuilder
has too much overhead for a small amount of concat.
EDIT:
Due to some vague aspects of what I'm asking, let me reformulate this.
Here's what happens:
- The main row is indexed.
- Parts of the main line are copied to
char[]
. char[]
converted to string
.
What I would like to do is merge 2 and 3, resulting in:
- The main row is indexed.
- Parts of the main line are copied to
string
(and the GC can keep its hands off it during the process by using the fixed
keyword correctly?)
And note that I cannot change the type of output from the string [], since this is an external library, and projects depend on it (backward compatibility).
Aidiakapi
source share