memtest.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <random>
int main() {
std::default_random_engine generator;
std::uniform_int_distribution<int> distribution(0,200000000);
printf("Start! %lu\n", sizeof(int));
int index = 0;
auto allocs = std::vector<char *>();
allocs.reserve(1000000);
while (char* ptr = (char *)malloc(1 << 20)) {
index++;
allocs.push_back(ptr);
printf("Malloced %d MB of memory\n", index);
for (int i = 0; i < 10000; i++)
allocs[distribution(generator)%allocs.size()][distribution(generator)%(1 << 10)] = distribution(generator);
for (int i = 0; i < 10000; i++)
printf("%d ", allocs[distribution(generator)%allocs.size()][distribution(generator)%(1 << 10)]);
printf("\n");
}
printf("Finish!\n");
return 0;
}