Advertisement
Guest User

Untitled

a guest
May 21st, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. //Filip Westerlund (fiwe1800)
  2. //2019-05-21
  3. //Datateknik
  4. //Objektbaserad programmering (i C++)
  5.  
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. void AllocateKiB();
  10. void AllocateGiB();
  11.  
  12. int main()
  13. {
  14. int KiBcount = 0;
  15. int GiBcount = 0;
  16. try
  17. {
  18. int option = -1;
  19. while (option != 0)
  20. {
  21. cout << "What do you want to do?" << endl << "1: Allocate 1 KiB" << endl << "2: Allocate 1 GiB" << endl << "0: Quit" << endl;
  22. if (cin >> option)
  23. {
  24. switch (option)
  25. {
  26. case 1:
  27. while (true)
  28. {
  29. AllocateKiB();
  30. KiBcount++;
  31.  
  32. if (KiBcount % 1000 == 0)
  33. {
  34. cout << KiBcount << " KiBs allocated" << endl;
  35. }
  36. }
  37. break;
  38. case 2:
  39. while (true)
  40. {
  41. AllocateGiB();
  42. GiBcount++;
  43. cout << GiBcount << " GiBs allocated" << endl;
  44. }
  45. break;
  46. }
  47. }
  48. else
  49. {
  50. option = -1;
  51. cin.clear();
  52. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  53. }
  54.  
  55. }
  56. }
  57. catch (bad_alloc e)
  58. {
  59. cerr << e.what() << endl;
  60. if (KiBcount > 0)
  61. {
  62. cout << KiBcount << " KiBs were allocated" << endl;
  63. }
  64. if (GiBcount > 0)
  65. {
  66. cout << GiBcount << " GiBs were allocated" << endl;
  67. }
  68. }
  69. int a;
  70. cin >> a;
  71. return 0;
  72. }
  73.  
  74. void AllocateKiB()
  75. {
  76. int8_t* newInt = new int8_t[1024];
  77. }
  78. void AllocateGiB()
  79. {
  80. int8_t* newInt = new int8_t[1024 * 1024 * 1024];
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement