I am trying to speed up a program which parses millions of strings, but sometimes I get a crash
Protected *s, *p
If j > 0
*p = *Buffer + j
*ptr = @*p
*ptr\s = Chr(0) ;Crash
*ptr = @*p
Any idea why?
Now j is verified that is it less than buffer which holds the string
When you assign a new string to *ptr\s, *ptr (which was pointing to *p which points to a string at *Buffer + j) may attempt to free the string memory that is pointed to by *p (before allocating new memory to receive the new string being assigned).
In my tests it would seem that because the new string Chr(0) is small it is just overwriting the previous string memory with the new value. If it instead tries to free the string memory and allocate new memory for the string it will cause a crash. I think it does this occasionally and when it does it causes your problem.
It might also occur if *p does not point to *Buffer (j <> 0). If an attempt is made to free the memory then, it would cause it to free memory at an invalid location (not the start) which is in the middle of the memory area pointed to by *Buffer.
If you are simply trying to overwrite the string at *Buffer + j with a #Null try using PokeS(*p, 0) instead. This will avoid any possible attempts to free and reallocate the affected memory.