Advertisement
Blade83

Create a Memory Leak

Mar 25th, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <new>
  3.  
  4. int main(void)
  5. {
  6.     std::cout << "START LOOP FOR 10 TIMES" << std::endl;
  7.     for (int s = 0; s < 10; s++)
  8.     {
  9.         try
  10.         {
  11.             int* memoryLeak = new int[100000000];
  12.         }
  13.         catch (std::bad_alloc &eception)
  14.         {
  15.             std::cout << "catch loop error (" << (s+1) << "/10): " << eception.what() << std::endl;
  16.         }
  17.     }
  18.  
  19.     // Speicherbelegung
  20.     //     length       int      kb      mb     loop    result
  21.     // (((100000000 * 4Bytes) * 1024) * 1024) * 10    = 3810 Mb
  22.  
  23.     std::cout << "END 10 TIMES" << std::flush;
  24.     system("PAUSE");
  25.     return EXIT_SUCCESS;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement