fork download
  1. #include <bits/stdc++.h>
  2.  
  3. char myHeap[1 << 20];
  4. int sz = 0;
  5.  
  6. void* operator new ( std::size_t count ) {
  7. std::cout << "Operator new is called, count = " << count << std::endl;
  8. sz += count;
  9. return myHeap + sz - count;
  10. }
  11.  
  12. void operator delete (void *ptr) {
  13. std::cout << "Operator delete is called" << std::endl;
  14. }
  15.  
  16. std::string s;
  17.  
  18. int main() {
  19. for (char c = 'a'; c <= 'z'; c++) {
  20. std::cout << "Adding char '" << c << "' to string" << std::endl;
  21. s.push_back(c);
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0s 4472KB
stdin
Standard input is empty
stdout
Adding char 'a' to string
Adding char 'b' to string
Adding char 'c' to string
Adding char 'd' to string
Adding char 'e' to string
Adding char 'f' to string
Adding char 'g' to string
Adding char 'h' to string
Adding char 'i' to string
Adding char 'j' to string
Adding char 'k' to string
Adding char 'l' to string
Adding char 'm' to string
Adding char 'n' to string
Adding char 'o' to string
Adding char 'p' to string
Operator new is called, count = 31
Adding char 'q' to string
Adding char 'r' to string
Adding char 's' to string
Adding char 't' to string
Adding char 'u' to string
Adding char 'v' to string
Adding char 'w' to string
Adding char 'x' to string
Adding char 'y' to string
Adding char 'z' to string
Operator delete is called