Skip to content

Instantly share code, notes, and snippets.

@gordinmitya
Last active June 25, 2018 17:06
Show Gist options
  • Save gordinmitya/a60cb201fca0ff8b181a581c0bea482a to your computer and use it in GitHub Desktop.
Save gordinmitya/a60cb201fca0ff8b181a581c0bea482a to your computer and use it in GitHub Desktop.
generate binary files with x64 pointers
#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