Created
June 10, 2018 22:07
-
-
Save eXpl0it3r/34d01e1b58f055bd91370e1c3a6420c3 to your computer and use it in GitHub Desktop.
Visual Studio - std::ftell performance issue - better example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _CRT_SECURE_NO_WARNINGS | |
#include <cstdio> | |
int main() | |
{ | |
// Search the first 32MiB for a Z character | |
constexpr auto maxToRead = 32 * 1024 * 1024; | |
auto f = std::fopen("test.dat", "rb"); | |
while (!std::feof(f) && (std::ftell(f) < maxToRead)) | |
{ | |
char c; | |
if (std::fread(&c, 1, 1, f) && (c == 'Z')) | |
{ | |
return 0; | |
} | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment