Created
September 7, 2016 17:13
-
-
Save daverigby/cb12778265545a2e90c79b0c5d4d14c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
#include <queue> | |
void* operator new(std::size_t sz) { | |
std::printf("global op new called, size = %zu\n",sz); | |
return std::malloc(sz); | |
} | |
void operator delete(void* ptr) noexcept | |
{ | |
std::puts("global op delete called"); | |
std::free(ptr); | |
} | |
int main() { | |
std::puts("Alloc std::queue<int>"); | |
std::queue<int> q; | |
} | |
// EOF | |
$ g++ --version | |
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609 | |
$ g++ -g -O3 -std=c++11 deque_mem_test.cc && ./a.out | |
Alloc std::queue<int> | |
global op new called, size = 64 | |
global op new called, size = 512 | |
global op new called, size = 64 | |
global op new called, size = 512 | |
global op delete called | |
global op delete called | |
global op delete called | |
global op delete called | |
// ?? Why you allocate memory?? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment