Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Filip Westerlund (fiwe1800)
- //2019-05-21
- //Datateknik
- //Objektbaserad programmering (i C++)
- #include <iostream>
- using namespace std;
- void AllocateKiB();
- void AllocateGiB();
- int main()
- {
- int KiBcount = 0;
- int GiBcount = 0;
- try
- {
- int option = -1;
- while (option != 0)
- {
- cout << "What do you want to do?" << endl << "1: Allocate 1 KiB" << endl << "2: Allocate 1 GiB" << endl << "0: Quit" << endl;
- if (cin >> option)
- {
- switch (option)
- {
- case 1:
- while (true)
- {
- AllocateKiB();
- KiBcount++;
- if (KiBcount % 1000 == 0)
- {
- cout << KiBcount << " KiBs allocated" << endl;
- }
- }
- break;
- case 2:
- while (true)
- {
- AllocateGiB();
- GiBcount++;
- cout << GiBcount << " GiBs allocated" << endl;
- }
- break;
- }
- }
- else
- {
- option = -1;
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- }
- }
- catch (bad_alloc e)
- {
- cerr << e.what() << endl;
- if (KiBcount > 0)
- {
- cout << KiBcount << " KiBs were allocated" << endl;
- }
- if (GiBcount > 0)
- {
- cout << GiBcount << " GiBs were allocated" << endl;
- }
- }
- int a;
- cin >> a;
- return 0;
- }
- void AllocateKiB()
- {
- int8_t* newInt = new int8_t[1024];
- }
- void AllocateGiB()
- {
- int8_t* newInt = new int8_t[1024 * 1024 * 1024];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement