Skip to content

Commit ca13611

Browse files
author
purofle
committed
Mergh origin main branch 'mariuszkurek-patch-1'
2 parents b51772e + 2de9f39 commit ca13611

File tree

1 file changed

+16
-45
lines changed

1 file changed

+16
-45
lines changed

src/main.cpp

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,28 @@
11
#include <iostream>
2-
#include <cstring>
32
using namespace std;
43

5-
long long FILL_SIZE;
6-
void fuckMemory();
7-
void fuckMemoryWithoutMemset();
8-
94
int main()
105
{
11-
int choose;
12-
cout << "Start FuckMemory(1)" << endl << "Start FuckMemory without memset - Harmless(2)" << endl;
13-
cout << endl << "Choose a mode(Default is \"Start FuckMemory\"): ";
14-
choose=getchar();
15-
cout << "Type a default memory size(MB): ";
16-
cin >> FILL_SIZE;
17-
FILL_SIZE *= 1024*1024;
18-
switch(choose)
19-
{
20-
case '2':
21-
fuckMemoryWithoutMemset();break;
22-
default:
23-
fuckMemory();
24-
}
25-
return 0;
26-
}
6+
cout << "Start FuckMemory (1)" << endl << "Start FuckMemory without fill - Harmless (2)" << endl;
7+
cout << endl << "Choose a mode (Default is \"Start FuckMemory\"): ";
8+
int choose = getchar();
279

28-
void fuckMemoryWithoutMemset()
29-
{
30-
long long memsize;
31-
memsize = 0;
32-
while(1)
33-
{
34-
if(getchar() != '\n')
35-
continue;
36-
memsize += FILL_SIZE;
37-
char *buf = new char[FILL_SIZE];
38-
cout << "Current memsize: " << memsize / 1024 / 1024 << "MB";
39-
//getchar();
40-
}
41-
}
10+
long long FILL_SIZE;
11+
cout << "Type a default memory size in MB: ";
12+
cin >> FILL_SIZE;
13+
FILL_SIZE *= 1024 * 1024;
4214

43-
void fuckMemory()
44-
{
45-
long long memsize;
46-
memsize = 0;
47-
while(1)
15+
long long memsize = 0;
16+
while (true)
4817
{
49-
if(getchar() != '\n')
18+
if (getchar() != '\n')
5019
continue;
5120
memsize += FILL_SIZE;
52-
char *buf = new char[FILL_SIZE];
53-
memset (buf,rand()%255, FILL_SIZE);
54-
cout << "Current memsize: " << memsize / 1024 / 1024 << "MB";
55-
//getchar();
21+
int *buf = new int[FILL_SIZE >> 2];
22+
if (choose != '2')
23+
fill(buf, buf + FILL_SIZE / 4, rand());
24+
cout << "Current memsize: " << memsize / 1024 / 1024 << " MB";
5625
}
26+
27+
return 0;
5728
}

0 commit comments

Comments
 (0)