Wednesday, February 6, 2013

how to write an operator new by yourself

void * operator new(size_t size)
{
     if(size==0)size=1;

while(1)
{
res=(void*)malloc(size);
if(res)
return res;

new_handler_globalHandler=set_new_handler(0);
set_new_handler(globalHandler);

if(globalHandler)
{
(*globalHandler)();
}
else
throw std::bad_alloc();
}
}

No comments:

Post a Comment