Skip to content

Instantly share code, notes, and snippets.

@eXpl0it3r
Created June 10, 2018 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eXpl0it3r/34d01e1b58f055bd91370e1c3a6420c3 to your computer and use it in GitHub Desktop.
Save eXpl0it3r/34d01e1b58f055bd91370e1c3a6420c3 to your computer and use it in GitHub Desktop.
Visual Studio - std::ftell performance issue - better example
#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