Og sp when using string.find(StringToFind); its dead fast! And it can locate a characters in a second even with a string\ buffer witch is 1 - 8 M bytes.
But when doing this
1 2 3 4 5 6 7 8 9
do {
// Sleep(1);
if (ptrPos > DataBuffer.length())
{
ptrPos = 0;
}
ptrPos += SearchData( DataBuffer, ptrPos);
//Sleep(1);
} while (ptrPos != string::npos && ptrPos <= DataBuffer.length());
Search Data is my function prototype looks like this. size_t SearchData(const std::string& Buffer, size_t Pos);
Pos is the position of string.find() + MatchString.length()
Thanks for any help on understanding the find function takes so long time when calling it in a loop and is dead fast on a singel call. May be worth to mention that the calls can look a bit difrent. string.find(strintofind);
In a loop its string.find(StringToFind, (size_t)PositionToStartSearchFrom)
SearchData returns Pos + the length of the string it found so i jumps over everything in the sub string that i just found and then starts from there next rotation..
yes its the same as Pos. ptrPos = Pos = ptrPos = Pos
If the function returns the new position to search from you should not use += on line 7. Pos + length of string is not necessary at the location after the string.
if MatchString = "w" then the function will return position 1 and not position 2
1 2 3
"hello world!"
^ ^
1 2
Use the return type of find instead of Pos in the return value.