I'm searching for few bytes in a char array. The problem is that on slower machines the process gets up to 90%+ cpu usage. How to prevent that? My code is:
for(long i = 0; i < size - 5; ) {
if (buff[++i] == 'f' && buff[++i] == 'i' && buff[++i] == 'l' && buff[++i] == 'e') {
printf("found at: %d\n", i);
}
}
EDIT: The string "file" is not null-terminated.
sleep()calls in there I don't see many options.sleepornanosleep(which I think MS doesn't implement, but there'sSleepor just use boost for Xplatform issues) is the only way I see how to solve this - obviously NOT sleeping after every loop iteration but creating two loops: Ie search through the first X characters, sleep Yms, repeat.