You have shown what works fastest for you, based on what is presumably a fairly decent spec PC not doing much else at the time... unfortunately the real usage isn't always like that.

I suspect you have a plenty of RAM available, but not every computer does - lots of people run fairly close the limit, even with brand new PC's (it is shocking how many pc makers still skimp on RAM, and then pre-install lots of memory hungry software ).

While your timings showed that the fixed size was the slowest (but by a usable amount), the careful use of memory means that in a situation where there is a limited amount of RAM available, it could easily become dramatically faster than the other methods (if virtual memory kicks in later than with the others, or not at all).


Unfortunately this is an area where the "best" method is case specific, depending on the amount of memory needed (which we don't know yet, all we know is that it involves strings), and the amount that is likely to be available.

There are several valid options here for coolcurrent4u to try, which should all be noticeably faster than the original... and of course if wanted we can help to optimise/re-design the routine as a whole too (maybe involving a replacement of this loop), which could possibly yield much bigger gains.

I think the best thing to do is wait for coolcurrent4u to comment on what has been suggested so far.