64,646
社区成员
发帖
与我相关
我的任务
分享
cout << "new\n";
char * p = new char[100000000000];
if (NULL == p)
{
cout << "new wrong !\n";
}
cout << "delete\n";
delete [] p;
p = NULL;
#include <iostream>
int main()
{
size_t *p;
try
{
do
{
p = new size_t[1024*1024*500];
cout<<"Allocating memory..."<<p<<endl;
if(p == NULL)
{
break;
}
}while(p);
}
catch(...)
{
cout<<endl<<"catch..."<<endl;
}
cout<<"Allocating OK!....."<<endl;
return 0;
}
/*
* main.cpp
*
* Created on: Jul 29, 2011
* Author: tyj
*/
#include <iostream>
#include <cstdlib>
using namespace std;
void my_new_handler()
{
cerr << "Unable to satisfy request for memory\n";
abort();
}
int main(int argc, char* argv[])
{
cout << "new\n";
set_new_handler(my_new_handler);
char *p = new char[1000000000000000L];
if (NULL == p)
{
cout << "new wrong !\n";
}
p[0L] = 'a';
p[99999999999L] = 'b';
cout << p[0L] << p[99999999999L] << endl;
cout << "delete\n";
delete [] p;
p = NULL;
return 0;
}
/*
* main.cpp
*
* Created on: Jul 29, 2011
* Author: tyj
*/
#include <iostream>
#include <cstdlib>
using namespace std;
void my_new_handler()
{
cerr << "Unable to satisfy request for memory\n";
abort();
}
int main(int argc, char* argv[])
{
cout << "new\n";
// set_new_handler(my_new_handler);
char *p = new char[100000000000000L];
if (NULL == p)
{
cout << "new wrong !\n";
}
p[0L] = 'a';
p[99999999999L] = 'b';
cout << p[0L] << p[99999999999L] << endl;
cout << "delete\n";
delete [] p;
p = NULL;
return 0;
}
cout << "new\n";
char * p = NULL;
while (1)
{
p = new char[1024*1024*500];// 500M
if (NULL == p)
{
cout << "new wrong !\n";
break;
}
}
cout << "delete\n";
delete [] p;
p = NULL;