-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRamStresser.cpp
57 lines (49 loc) · 1.29 KB
/
RamStresser.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// RamStresser.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <chrono>
#include <thread>
struct Filler {
double a, b, c, d; //32 bytes
Filler() {
a = 1;
}
};
using std::cout;
using std::endl;
using std::cin;
using std::vector;
void fillPart(long long howMany, vector<Filler> &vec)
{
for (long long i = 0; i < howMany; i++)
vec.push_back(Filler());
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); //this delay is added to make memory filling slower
}
void clearPart(long long howMany, vector<Filler> &vec)
{
auto initialSize = vec.size();
vec.erase(vec.begin(), vec.begin() + howMany);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
int main()
{
long long megabytes;
cout << "How much RAM do you have (in megabytes): ";
cin >> megabytes;
long long bytes = megabytes * 1000 * 1000; //not 1024 because OS and whatnot wants some of it too
long long maxElements = bytes / sizeof(Filler);
vector<Filler> megaVec;
for (int i = 1; i <= 10; i++)
{
cout << "Filling " << i * 10 << "% RAM" << endl;
fillPart(maxElements / 10, megaVec);
}
for (int i = 1; i <= 10; i++)
{
clearPart(maxElements / 10, megaVec);
cout << "Clearing " << i * 10 << "% RAM" << endl;
}
return 0;
}