3
我已經將其設置爲1啓用MALLOC_CHECK_
(試圖與2和3也一樣),但我不認爲它報告任何問題與下面的C++程序:MALLOC_CHECK_不報告違規
int n = atoi(argv[1]);
std::cout<<"n = "<<n<<std::endl;
char *buf = new char[n];
for (int i = 0;i < n*n; i++)
{
buf++;
*buf = 'x';
}
std::cout<<"done"<<std::endl;
上午我在這裏丟失什麼?
你沒有做'malloc'。 – Naveen
'char * buf =(char *)malloc(n);' – Maroun
operator new可以調用malloc。在我的環境中(libstdC++)它是[link](http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/libsupc%2B%2B/new_op.cc?revision=193295&view=markup ) – user947158