📄 xmem.h
字号:
/*****************************************************************************/
/*
XMEM.H - Extended C/C++ Dynamic Memory Control And Debug Library
Copyright (C) Juergen Mueller (J.M.) 1987-2008
All rights reserved.
You are expressly prohibited from selling this software in any form
or removing this notice.
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, THE
IMPLIED WARRANTIES OF MERCHANTIBILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR SHALL NOT BE LIABLE FOR
ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. THE ENTIRE RISK
AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM AND DOCUMENTATION
IS WITH YOU.
Permission to modify the code and to distribute modified code is granted,
provided the above notices are retained, and a notice that the code was
modified is included with the above copyright notice.
written by: Juergen Mueller, D-70806 Kornwestheim, GERMANY
FILE : XMEM.H
REVISION : 07-Apr-2008
20:50:57
*/
/*****************************************************************************/
#ifndef __XMEM_H_INCLUDED__
#define __XMEM_H_INCLUDED__
/*****************************************************************************/
/**** macro definitions for the XMEM package ****/
/*****************************************************************************/
/* XMEM: 0 => memory test OFF, otherwise ON */
/* must be defined outside, best choice is as a compiler option -D */
#ifndef XMEM /* do not rely on 'defined' */
#define XMEM 0 /* default: no XMEM memory debugging */
#endif
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
#if XMEM /**** if XMEM package enabled ****/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/**** get some necessary includes ****/
/*****************************************************************************/
#include <stdio.h> /* necessary to get type 'size_t' */
#ifndef va_start /* if not already included */
#include <stdarg.h> /* necessary to get type 'va_list' */
#endif
/*****************************************************************************/
/*****************************************************************************/
/**** macros to customize the behaviour of the XMEM package ****/
/*****************************************************************************/
/*****************************************************************************/
/* these macros can be user defined outside, best choice is as a compiler option -D */
/* check, if macros are predefined and set to defined values if not */
#ifndef XMEM_CPP
#ifdef __cplusplus /* if C++ compilation */
#define XMEM_CPP 1 /* default 1: trace C++ new/delete operators */
#else
#define XMEM_CPP 0 /* default 0: disabled if C compilation */
#endif
#endif
#ifndef XMEM_ASPECTCPP
#define XMEM_ASPECTCPP 0 /* default 0: no AspectC++ code */
#endif
#if XMEM_ASPECTCPP
#if !defined(__cplusplus) /* AscpetC++ requires C++ compilation */
#pragma message(">>> XMEM_ASPECTCPP disabled, requires C++ compilation!!!")
#undef XMEM_ASPECTCPP
#define XMEM_ASPECTCPP 0
#endif
#endif
#ifndef XMEM_QUIET /* quiet mode -> "Garbage Collection" && "Memory Clean-Up" */
#define XMEM_QUIET 0 /* default 0: no quiet operation, produce messages if necessary */
#endif
#if XMEM_QUIET
#ifdef XMEM_FREE_INCREASE_ORDER
#undef XMEM_FREE_INCREASE_ORDER
#endif
#define XMEM_FREE_INCREASE_ORDER 0 /* if quiet operation no special ordering necessary (performance improvement) */
#endif
#ifndef XMEM_FORCE_OUTPUT /* force output, this overrides quiet operation!!! */
#define XMEM_FORCE_OUTPUT 0 /* default 0: no forced output */
#endif
#ifndef XMEM_CPP_INIT
#ifdef __cplusplus /* if C++ compilation */
#if !XMEM_QUIET /* no quiet operation */
#define XMEM_CPP_INIT 1 /* 1: perform XMEM init with static C++ object */
#else /* quiet operation */
#define XMEM_CPP_INIT 0 /* 0: perform no XMEM init with static C++ object */
#endif
#else
#define XMEM_CPP_INIT 0 /* 0: perform no XMEM init with static C++ object */
#endif
#endif
#ifdef __cplusplus /* if C++ compilation */
#define XMEM_CPP_DELETE_STACK 1 /* correct handling of source location tracing for nested calls to C++ operator delete */
#endif
#ifndef XMEM_C_INTERFACE
#define XMEM_C_INTERFACE 0 /* default 0: assume language specific default interface */
#endif /* 1: enforce C interface "extern C" (useful in mixed C/C++ programs) */
/**** Microsoft Detours function call redirection ****/
#ifdef __cplusplus /* if C++ compilation */
#if _WIN32 && defined(_MSC_VER) && (_MSC_VER >= 1300)
#ifndef XMEM_ALLOC_CALL
#define XMEM_ALLOC_CALL 0 /* default 0: no library call redirection */
#endif /* 1: replace library calls and redirect them to XMEM functions */
#else
#if XMEM_ALLOC_CALL
#pragma message(">>> XMEM_ALLOC_CALL disabled!!!")
#endif
#undef XMEM_ALLOC_CALL
#define XMEM_ALLOC_CALL 0 /* not supported - default 0 */
#endif
#else /* if not C++ */
#if XMEM_ALLOC_CALL
#pragma message(">>> XMEM_ALLOC_CALL disabled!!!")
#endif
#undef XMEM_ALLOC_CALL
#define XMEM_ALLOC_CALL 0 /* not supported - default 0 */
#endif /* end if C++ compilation */
#if XMEM_ALLOC_CALL
#ifndef XMEM_DETOURS
#if 1 /* select the Microsoft Detours version */
#define XMEM_DETOURS 1 /* Microsoft Detours v1.5 */
#else
#define XMEM_DETOURS 2 /* Microsoft Detours v2.1 */
#endif
#endif
#endif
#if XMEM_ALLOC_CALL
#if XMEM_C_INTERFACE
#pragma message(">>> XMEM_C_INTERFACE disabled due to XMEM_ALLOC_CALL!!!")
#endif
#undef XMEM_C_INTERFACE
#define XMEM_C_INTERFACE 0 /* XMEM_C_INTERFACE = 1 conflicts with XMEM_ALLOC_CALL = 1 */
#endif
/**** home-brew function call redirection ****/
#ifdef __cplusplus /* if C++ compilation */
#ifdef _WIN32
#ifndef XMEM_ALLOC_LIB
#define XMEM_ALLOC_LIB 0 /* default 0: no library call redirection */
#endif /* 1: replace library calls and redirect them to XMEM functions */
#else
#if XMEM_ALLOC_LIB
#pragma message(">>> XMEM_ALLOC_LIB disabled (requires Win32)!!!")
#endif
#undef XMEM_ALLOC_LIB
#define XMEM_ALLOC_LIB 0 /* not supported - default 0 */
#endif
#else /* if not C++ */
#if XMEM_ALLOC_LIB
#pragma message(">>> XMEM_ALLOC_LIB disabled (requires C++)!!!")
#endif
#undef XMEM_ALLOC_LIB
#define XMEM_ALLOC_LIB 0 /* not supported - default 0 */
#endif /* end if C++ compilation */
#if XMEM_ALLOC_LIB
#if XMEM_C_INTERFACE
#pragma message(">>> XMEM_C_INTERFACE disabled due to XMEM_ALLOC_LIB!!!")
#endif
#undef XMEM_C_INTERFACE
#define XMEM_C_INTERFACE 0 /* XMEM_C_INTERFACE = 1 conflicts with XMEM_ALLOC_LIB = 1 */
#endif
#ifndef XMEM_WHERE
#define XMEM_WHERE 1 /* default 1: trace allocation call locations */
#endif
#if (XMEM_WHERE == 0) && (XMEM_CPP != 0)
#undef XMEM_WHERE
#define XMEM_WHERE 1
#pragma message(">>> XMEM_WHERE enabled due to XMEM_CPP!!!")
#endif
#ifndef XMEM_CALLSTACK
#define XMEM_CALLSTACK 0 /* default 0: no call stack trace */
#endif
#if XMEM_CALLSTACK
#if !defined(__cplusplus) && !defined(_MSC_VER) && !defined(_WIN32)
#pragma message(">>> XMEM_CALLSTACK disabled due to missing preconditions (C++, Win32, Microsoft C++)!!!")
#undef XMEM_CALLSTACK
#define XMEM_CALLSTACK 0 /* XMEM_CALLSTACK requires C++, Win32, Microsoft C++ */
#endif
#endif
#ifndef XMEM_CALLSTACK_HASH
#if XMEM_CALLSTACK
#define XMEM_CALLSTACK_HASH 1 /* default 1: call stack hash optimization (experimental) */
#else
#define XMEM_CALLSTACK_HASH 0
#endif
#endif
#if _WIN32 /* if WIN32 */
#ifndef XMEM_THREAD
#define XMEM_THREAD 0 /* default 0: no multi threading support */
#endif
#else /* else not WIN32 */
#ifdef XMEM_THREAD
#if XMEM_THREAD
#pragma message(">>> XMEM_THREAD disabled (requires Win32)!!!")
#endif
#undef XMEM_THREAD
#endif
#define XMEM_THREAD 0
#endif /* endif */
#ifndef XMEM_VISIT
#define XMEM_VISIT 0 /* default 0: do not show last visited location */
#endif
#ifndef XMEM_FREENULL
#define XMEM_FREENULL 1 /* default 1: set freed pointer to NULL (to force access violation for further use) */
#endif
#ifndef XMEM_WITHIN
#define XMEM_WITHIN 0 /* default 0: no check within memory blocks */
#endif /* NOTE: if enabled this feature is not completely tested and reliable */
#ifndef XMEM_GUARD
#define XMEM_GUARD 1 /* default 1: surround memory blocks with guard regions */
#endif /* to catch buffer under- and overflows */
#if XMEM_ASPECTCPP
#if XMEM_GUARD
#pragma message(">>> XMEM_GUARD disabled due to XMEM_ASPECTCPP!!!")
#endif
#undef XMEM_GUARD
#define XMEM_GUARD 0 /* XMEM_GUARD = 1 conflicts with XMEM_ASPECTCPP = 1 */
#endif
#ifndef XMEM_ALLOCFILL
#define XMEM_ALLOCFILL 1 /* default 1: fill allocated memory with pattern */
#endif /* useful to detect if memory is really used */
#ifndef XMEM_FREEFILL
#define XMEM_FREEFILL 1 /* default 1: fill freed memory with pattern */
#endif /* useful to detect memory writes after freeing */
#ifndef XMEM_USED
#define XMEM_USED 1 /* default 1: test allocated memory for usage */
#endif
#ifndef XMEM_TEST_NULL
#define XMEM_TEST_NULL 1 /* default 1: warning if allocation failed and exit */
#endif /* since not all calls to memory function may check return values XME can do this internally */
#ifndef XMEM_ALLOC_FAIL_WARN
#define XMEM_ALLOC_FAIL_WARN 1 /* default 1: warn if allocation fails */
#endif
#ifndef XMEM_WARN_BAD
#define XMEM_WARN_BAD 1 /* default 1: warning if freeing bad pointer */
#endif
#ifndef XMEM_REALLOC_ILLEGAL
#define XMEM_REALLOC_ILLEGAL 0 /* default 0: no realloc with illegal pointers */
#endif
#ifndef XMEM_ALLOCA
#if defined(_MSC_VER) || (__GNUC__ && !defined(__CYGWIN__) && !defined(__linux__))
#define XMEM_ALLOCA 1 /* 1: alloca() handling */
#else
#define XMEM_ALLOCA 0 /* 0: no alloca() handling */
#endif
#endif
#ifndef XMEM_STR
#define XMEM_STR 1 /* default 1: trace strxxx() functions for problems */
#endif
#ifndef XMEM_MEM
#define XMEM_MEM 1 /* default 1: trace memxxx() functions for problems */
#endif
#if XFILE /* relations / interfacing with XFILE package */
#if XMEM_FILE
#pragma message(">>> XMEM_FILE disabled!!!")
#endif
#ifdef XMEM_FILE
#undef XMEM_FILE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -