Last active
June 25, 2018 17:06
-
-
Save gordinmitya/a60cb201fca0ff8b181a581c0bea482a to your computer and use it in GitHub Desktop.
generate binary files with x64 pointers
This file contains 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
#include <cstdio> | |
#include <cstdlib> | |
#define PTYPE int | |
#define COUNT 105000 // empiric const to make 40M file | |
#define BUFFER_SIZE 10 | |
#define VARIATION 500100 // allocate "huge" piece of memory | |
int main() { | |
FILE *orderedFile = fopen("ordered.bin", "wb"); | |
FILE *shuffledFile = fopen("shuffled.bin", "wb"); | |
PTYPE objects[VARIATION]; | |
for (int i = 0; i < COUNT; ++i) { | |
PTYPE *orderedBuffer[BUFFER_SIZE]; | |
PTYPE *shuffledBuffer[BUFFER_SIZE]; | |
for (int j = 0; j < BUFFER_SIZE; ++j) { | |
orderedBuffer[j] = &objects[(i * COUNT + j) % VARIATION]; | |
shuffledBuffer[j] = &objects[rand() % VARIATION]; | |
} | |
fwrite(orderedBuffer, sizeof(PTYPE), 100, orderedFile); | |
fwrite(shuffledBuffer, sizeof(PTYPE), 100, shuffledFile); | |
} | |
fclose(orderedFile); | |
fclose(shuffledFile); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment