04-18-2025, 08:29 PM
(04-18-2025, 07:31 PM)mdijkens Wrote: What is flawed?
My point posting this was performance with big strings...
This is veery slow with big strings
Code: (Select All)
m = _MemNew(Len(content$) * 2): mp = 0: pp = 1
Only thing I wonder about.
1) Is the line above that I left in the quote. Why is the size LEN * 2? How are you certain that you're not going to run into overflow issues and such with it?
For example, let's just say this is my string: "AA"
I want to replace "A" with "Hello"... A length of 4 isn't going to hold my 10 bytes for "HelloHello".
Seems to be safe, you'd need to run a routine once to search the string for the number of instances of "A" in it, and then use that to calculate how much larger the buffer would need to be. (Hello is 5 characters, A is 1, so the increase is 4* the number of instances of A in the program. In this case, we start with the original size of 2, then increase by 2 * 4, which gives us the 10 bytes needed to hold the buffer without overflow or wasted memory usage.)
2) Once you have an *exact* size and don't need to worry about overflowing the buffer, you can then $CHECKING:OFF around the rest of that Function, speeding it up and making up for the search/sizing time, *perhaps* even running faster in the long run, without having such concern for extreme memory usage and such.