我正在使用以下示例了解缓存的工作原理:
\n#include <stdio.h>\n#include <stdint.h>\n#include <stdlib.h>\n\ntypedef uint32_t data_t;\nconst int U = 10000000; // size of the array. 10 million vals ~= 40MB\nconst int N = 100000000; // number of searches to perform\n\nint main() {\n data_t* data = (data_t*) malloc(U * sizeof(data_t));\n if (data == NULL) {\n free(data);\n printf("Error: not enough memory\\n");\n exit(-1);\n }\n\n // fill up the array with sequential (sorted) values.\n int i;\n for (i = 0; i < U; i++) {\n data[i] = i;\n }\n\n printf("Allocated array of …Run Code Online (Sandbox Code Playgroud)