Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- char myHeap[1 << 20];
- int sz = 0;
- void* operator new ( std::size_t count ) {
- std::cout << "Operator new is called, count = " << count << std::endl;
- sz += count;
- return myHeap + sz - count;
- }
- // it's necessary as call to delete will be made to deallocate memory
- // allocated by new, since we allocated memory from array we need not
- // to free it in delete function since the array is going to destroy itself
- // void operator delete (void *ptr) {}
- void operator delete (void *ptr) {
- std::cout << "Operator delete is called" << std::endl;
- }
- std::string s;
- int main() {
- for (char c = 'a'; c <= 'z'; c++) {
- std::cout << "Adding char '" << c << "' to string" << std::endl;
- s.push_back(c);
- }
- // own *p = new own();
- return 0;
- }
Add Comment
Please, Sign In to add comment