Files
admin
base
basedrv
boot
busdrv
cluster
cmd
crts
asms
crtw32
doc
fpw32
langapi
libw32
inc64
include
sys
algorithm
assert.h
bitset
cassert
cctype
cerrno
cfloat
ciso646
climits
clocale
cmath
complex
conio.h
crtdbg.h
csetjmp
csignal
cstdarg
cstddef
cstdio
cstdlib
cstring
ctime
ctype.h
cwchar
cwctype
deque
direct.h
dos.h
dvec.h
eh.h
emmintrin.h
errno.h
exception
excpt.h
fcntl.h
float.h
fpieee.h
fstream
fstream.h
functional
fvec.h
hash_map
hash_set
io.h
iomanip
iomanip.h
ios
ios.h
iosfwd
iostream
iostream.h
iso646.h
istream
istream.h
iterator
ivec.h
limits
limits.h
list
locale
locale.h
malloc.h
map
math.h
mbctype.h
mbstring.h
memory
memory.h
minmax.h
mm3dnow.h
mmintrin.h
new
new.h
numeric
ostream
ostream.h
process.h
queue
rtcapi.h
search.h
set
setjmp.h
setjmpex.h
share.h
signal.h
sstream
stack
stdarg.h
stddef.h
stdexcept
stdexcpt.h
stdio.h
stdiostr.h
stdlib.h
stl.h
streamb.h
streambuf
string
string.h
strstrea.h
strstream
tchar.h
time.h
typeinfo
typeinfo.h
use_ansi.h
useoldio.h
utility
valarray
varargs.h
vector
wchar.h
wctype.h
xcomplex
xdebug
xhash
xiosbase
xlocale
xlocinfo
xlocinfo.h
xlocmes
xlocmon
xlocnum
xloctime
xmath.h
xmemory
xmmintrin.h
xstddef
xstring
xtree
xutility
ymath.h
yvals.h
lib
oldnames
tools
buildcrt.nt
dirs
msvcirt.rc
msvcirt.src
msvcprt.rc
msvcprt.src
msvcrt.rc
msvcrt.src
msvcrt40.rc
msvcrt40.src
syscrt.rc
syscrt.src
syscrt64.rc
syscrt64.src
sysirt.rc
sysirt.src
sysirt64.rc
sysirt64.src
sysprt.rc
sysprt.src
sysprt64.rc
sysprt64.src
srcrel
cb.cmd
clean.bat
clean.cmd
cleanbld.cmd
clns_bld.bat
depsed.sed
dirs
log.txt
log_64.txt
log_v40.txt
log_v41.txt
log_v42.txt
log_v50.txt
log_v60.txt
make.cmd
makefile
makefile.inc
makefile.sub
mk.bat
mkbld.cmd
ntia64bld.cmd
prebld.sed
rmdepend.bat
ddk
dload
dloadhandler
efiutil
eventlog
firmware
fs
fsrec
hals
headless
inc
mspatch
mvdm
ntdll
ntdllsym
ntos
ntsetup
pnp
published
qfe
remoteboot
screg
seaudit
strsafe
stublibs
subsys
testlockout
tools
urtl
wdmdrv
wdmlib
win32
wmi
wow64
xip
zlib
dirs
prerelease.inc
project.mk
com
developer
drivers
ds
enduser
inetcore
inetsrv
loc
mergedcomponents
multimedia
net
printscan
public
published
sdktools
shell
termsrv
tools
windows
dirs
makefil0
2025-04-27 07:49:33 -04:00

143 lines
3.6 KiB
Plaintext

// debug heap support header for Microsoft
#pragma once
#ifndef _XDEBUG_
#define _XDEBUG_
#pragma pack(push,8)
#pragma warning(push,3)
// SUPPORT FOR DEBUG HEAP
#if !defined(_DEBUG)
#define _NEW_CRT new
#define _DELETE_CRT(_P) delete (_P)
#define _DELETE_CRT_VEC(_P) delete[] (_P)
#define _STRING_CRT string
#else
#include <xmemory>
#include <xstring>
_STD_BEGIN
struct _DebugHeapTag_t
{ // placement new tag type to select debug CRT heap
int _Type;
};
extern _CRTIMP2 const _DebugHeapTag_t _DebugHeapTag;
_STD_END
_CRTIMP2 void * __cdecl
operator new(size_t, const std::_DebugHeapTag_t&, char *, int)
_THROW1(std::bad_alloc); // allocate from the debug CRT heap
_CRTIMP2 void * __cdecl
operator new[](size_t, const std::_DebugHeapTag_t&, char *, int)
_THROW1(std::bad_alloc); // allocate array from the debug CRT heap
_CRTIMP2 void __cdecl
operator delete(void *, const std::_DebugHeapTag_t&, char *, int)
_THROW0(); // delete if new for debug CRT heap fails
_CRTIMP2 void __cdecl
operator delete[](void *, const std::_DebugHeapTag_t&, char *, int)
_THROW0(); // delete if array new for debug CRT heap fails
#define _NEW_CRT new(std::_DebugHeapTag, __FILE__, __LINE__)
#define _DELETE_CRT(_P) std::_DebugHeapDelete(_P)
#define _DELETE_CRT_VEC(_P) std::_DebugHeapDelete((void *)_P)
#define _STRING_CRT _DebugHeapString
_STD_BEGIN
// TEMPLATE FUNCTION _DebugHeapDelete
template<class _Ty>
void _DebugHeapDelete(_Ty *_Ptr)
{ // delete from the debug CRT heap even if operator delete differs
if (_Ptr != 0)
{
_Ptr->~_Ty();
// delete as _NORMAL_BLOCK, not _CRT_BLOCK, since we might have
// facets allocated by normal new.
free(_Ptr);
}
}
// TEMPLATE CLASS _DebugHeapAllocator
template<class _Ty>
class _DebugHeapAllocator
: public allocator<_Ty>
{ // an allocator which uses the debug CRT heap
public:
template<class _Other>
struct rebind
{ // convert _DebugHeapAllocator<_Ty> to _DebugHeapAllocator<_Other>
typedef _DebugHeapAllocator<_Other> other;
};
template<class _Other>
pointer allocate(size_type _Count, const _Other *)
{ // allocate array of _Count elements, ignore hint
return (_Ty *)_NEW_CRT char[_Count * sizeof(_Ty)];
}
pointer allocate(size_type _Count)
{ // allocate array of _Count elements
return (_Ty *)_NEW_CRT char[_Count * sizeof(_Ty)];
}
void deallocate(pointer _Ptr, size_type)
{ // deallocate object at _Ptr, ignore size
_DELETE_CRT_VEC(_Ptr);
}
};
// CLASS _DebugHeapString
class _DebugHeapString
: public basic_string<char, char_traits<char>, _DebugHeapAllocator<char> >
{ // a version of std::string allocated on the debug CRT heap
public:
typedef _DebugHeapString _Myt;
typedef basic_string<char, char_traits<char>, _DebugHeapAllocator<char> >
_Mybase;
typedef char _Elem;
_DebugHeapString()
: _Mybase()
{ // construct empty string
}
_DebugHeapString(const _Myt& _Right)
: _Mybase(_Right)
{ // construct by copying _Right
}
_DebugHeapString(const _Elem *_Ptr)
: _Mybase(_Ptr)
{ // construct from [_Ptr, <null>)
}
_DebugHeapString(const string &_Str)
: _Mybase(_Str.c_str())
{ // construct from std::string
}
operator string() const
{
return string(c_str());
}
};
_STD_END
#endif /* _DEBUG */
#pragma warning(pop)
#pragma pack(pop)
#endif /* _XDEBUG_ */
/*
* Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
V3.10:0009 */