5 ms·
Whoa. I'm assuming I'm not doing enough String.Splits to worry about performance, but what's my alternative? Looping through the string myself?
by voltagex_ 12y ago
Whoa. I'm assuming I'm not doing enough String.Splits to worry about performance, but what's my alternative? Looping through the string myself?
- MichaelGG 12y agoThat's just one example. There's plenty of APIs that force garbage to be created for no good reason. For string.split what I've done when it was critical, is to statically allocate an array for each type of split. For other APIs, I'd create a state object for each request or piece of work that contains assorted buffers and other temp objects, then pass it around as needed. Ugly, but at high processing rates, every allocation counts.
- pmcg 12y agoThere can be two allocations when you call String.Split, one at the calling site where you create the array of delimiters to pass in, and one inside that creates the String[] to return. The parent refers to the first, which you can avoid by creating your char[] of delimiter[s] once and reusing it.
- emjaygee 12y agoSome people have built string processing libraries which operate on struct which have a string object reference and an index to the first character and a length. This lets you slice etc the strings without forcing any heap allocations.
- readerrrr 12y agoYour comment is absolutely adorable, for anyone writing C code. :-)