Created
January 3, 2023 02:46
-
-
Save Blizzardo1/518cac0aa738132ea475a305f6fcba28 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <stdlib.h> | |
#define PAGE_SIZE 511 /* The Page Size (Any higher on the stack and it will cause a segfault) */ | |
#define TLB_ENTRIES 64 /* The amount of Translation Lookaside Buffer Entries */ | |
#define M (PAGE_SIZE * TLB_ENTRIES) /* The distance between the memory addresses accessed by the loop (64KB)*/ | |
#define N (M * TLB_ENTRIES) /* The size of the array */ | |
// M is 256 | |
// N is 16384 | |
/* | |
Such as that an int is 4 bytes, the size of the array is N * 4 = 16384 * 4 = 65536 bytes. | |
*/ | |
int main(void) { | |
// int X2[N] = {0}; // Causes a segmentation fault (stack overflow) when N is 2KB or 2048 | |
int X[N] = {0}; | |
if (X == NULL) { | |
printf("Error: malloc failed to allocate memory.\n"); | |
return EXIT_FAILURE; | |
} | |
int step = M+1; | |
for (int i = 0; i < N; i += step) | |
X[i] = X[i] + 1; | |
for(int i = 0; i < N; i++) { | |
if(i % TLB_ENTRIES == 0) | |
if (X[i] == 1) | |
printf("%d", X[i]); | |
else | |
printf("@"); | |
else | |
printf(""); | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment