fork download
  1. #include <new>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <memory>
  5.  
  6. struct s {
  7. static void *operator new(std::size_t size) {
  8. std::cout << "allocate\n";
  9. if (void *ptr = std::malloc(size)) {
  10. return ptr;
  11. }
  12. throw std::bad_alloc();
  13. }
  14. static void operator delete(void *ptr) {
  15. std::cout << "deallocate\n";
  16. std::free(ptr);
  17. }
  18. };
  19.  
  20. int main() {
  21. std::unique_ptr<s> u(new s);
  22. }
  23.  
Success #stdin #stdout 0s 3016KB
stdin
Standard input is empty
stdout
allocate
deallocate