You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.3 KiB
72 lines
2.3 KiB
/***
|
|
*new.cxx - defines C++ new routine
|
|
*
|
|
* Copyright (c) 1990-2001, Microsoft Corporation. All rights reserved.
|
|
*
|
|
*Purpose:
|
|
* Defines C++ new routine.
|
|
*
|
|
*Revision History:
|
|
* 05-07-90 WAJ Initial version.
|
|
* 08-30-90 WAJ new now takes unsigned ints.
|
|
* 08-08-91 JCR call _halloc/_hfree, not halloc/hfree
|
|
* 08-13-91 KRS Change new.hxx to new.h. Fix copyright.
|
|
* 08-13-91 JCR ANSI-compatible _set_new_handler names
|
|
* 10-30-91 JCR Split new, delete, and handler into seperate sources
|
|
* 11-13-91 JCR 32-bit version
|
|
* 02-16-94 SKS Move set_new_handler functionality here from malloc()
|
|
* 03-01-94 SKS _pnhHeap must be declared in malloc.c, not here
|
|
* 03-03-94 SKS New handler functionality moved to malloc.c but under
|
|
* a new name, _nh_malloc().
|
|
* 02-01-95 GJF #ifdef out the change above for the Mac (temporary).
|
|
* 05-01-95 GJF Spliced on winheap version.
|
|
* 05-08-95 CFW Turn on new handling for Mac.
|
|
* 05-22-98 JWM Support for KFrei's RTC work, and operator new[].
|
|
* 07-28-98 JWM RTC update.
|
|
* 11-04-98 JWM Split off new[] to new2.cpp for better granularity.
|
|
* 12-18-98 GJF Changes for 64-bit size_t.
|
|
* 05-26-99 KBF Updated RTC hook func params
|
|
* 02-20-02 BWT Reduce the call frame by calling heap_alloc directly (better DW traces)
|
|
*
|
|
*******************************************************************************/
|
|
|
|
|
|
#include <cruntime.h>
|
|
#include <malloc.h>
|
|
#include <new.h>
|
|
#include <stdlib.h>
|
|
#include <winheap.h>
|
|
#include <rtcsup.h>
|
|
#include <internal.h>
|
|
|
|
void * operator new( size_t cb )
|
|
{
|
|
void *res;
|
|
|
|
// validate size
|
|
if (cb > _HEAP_MAXREQ)
|
|
res = NULL;
|
|
else {
|
|
for (;;) {
|
|
|
|
// allocate memory block
|
|
res = _heap_alloc(cb);
|
|
|
|
// if successful allocation, return pointer to memory
|
|
|
|
if (res)
|
|
break;
|
|
|
|
// call installed new handler
|
|
if (!_callnewh(cb))
|
|
break;
|
|
|
|
// new handler was successful -- try to allocate again
|
|
}
|
|
}
|
|
|
|
RTCCALLBACK(_RTC_Allocate_hook, (res, cb, 0));
|
|
|
|
return res;
|
|
}
|
|
|