⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmem.h

📁 Extended C/C++ Dynamic Memory Control And Debug Library
💻 H
📖 第 1 页 / 共 3 页
字号:
void   *xmem_memchr(const void *, int, size_t           _WHERE(const char *, const char *, unsigned long));
int     xmem_memcmp(const void *, const void *, size_t  _WHERE(const char *, const char *, unsigned long));
void   *xmem_memcpy(void *, const void *, size_t        _WHERE(const char *, const char *, unsigned long));
int     xmem_memicmp(const void *, const void *, size_t _WHERE(const char *, const char *, unsigned long));
void   *xmem_memmove(void *, const void *, size_t       _WHERE(const char *, const char *, unsigned long));
void   *xmem_memset(void *, int, size_t                 _WHERE(const char *, const char *, unsigned long));

char   *xmem_fgets(char *, int, FILE *            _WHERE(const char *, const char *, unsigned long));
size_t  xmem_fread(void *, size_t, size_t, FILE * _WHERE(const char *, const char *, unsigned long));

#if XMEM_C_INTERFACE    /******** C interface (for C++) ********/
#ifdef __cplusplus
}
#endif
#endif

#ifdef __cplusplus      /******** C++ specific stuff ********/
#if XMEM_CPP            /**** if XMEM C++ handling enabled ****/

#define XMEM_CRITICAL_OPERATOR      0   /* default 0: disable some C++ opeartors (in some configurations they did not work) */

/* prepare for special array [] operators */
#if __GNUC__
 #if (__GNUC__ <= 2) && (__GNUC_MINOR__ < 6)    /* <= GNU-C 2.5.9 */
  #define XMEM_NEWARRAY         0
  #define XMEM_DELETEARRAY      0
 #else                                          /* >= GNU-C 2.6.0 (tested with GNU-C 3.23) */
  #define XMEM_NEWARRAY         1
  #define XMEM_DELETEARRAY      1
 #endif
#elif defined(_MSC_VER)
 #if _MSC_VER < 1100                            /* MS VC++ before version 5.0 */
  #define XMEM_NEWARRAY         0
  #define XMEM_DELETEARRAY      0
 #else                                          /* MS VC++ 5.0 or higher */
  #define XMEM_NEWARRAY         1
  #define XMEM_DELETEARRAY      1
 #endif
#else                                           /* dummy section for all other compilers (may change in future) */
 #define XMEM_NEWARRAY          0               /* if necessary insert additional sections for other compilers */
 #define XMEM_DELETEARRAY       0
#endif

#endif                  /* end if XMEM_CPP */
#endif                  /******** end if C++ specific stuff ********/

/*****************************************************************************/
#ifndef __XMEM__        /**** if not in XMEM implementation ****/
/*****************************************************************************/

/**** macro replacements for XMEM specific functions ****/

/* in normal source files use only the macro version so that parameters are set by default */
#define xmem_showstatus()           xmem_showstatus(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_check_free()           xmem_check_free(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_check_free_virtual(a)  xmem_check_free_virtual(a,_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_check_ptr(a)           xmem_check_ptr((a),_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_overwrite()            xmem_overwrite(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_set_memtrace(a)        xmem_set_memtrace((a),_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_enable_memtrace()      xmem_enable_memtrace(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_disable_memtrace()     xmem_disable_memtrace(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_get_alloc_nr()         xmem_get_alloc_nr(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_set_trace_alloc(a)     xmem_set_trace_alloc((a),_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_reset_trace_alloc()    xmem_reset_trace_alloc(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_set_trace_free(a)      xmem_set_trace_free((a),_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_reset_trace_free()     xmem_reset_trace_free(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_set_max_heapsize(a)    xmem_set_max_heapsize((a),_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_get_max_heapsize()     xmem_get_max_heapsize(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_set_stress_ratio(a)    xmem_set_stress_ratio((a),_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_get_stress_ratio()     xmem_get_stress_ratio(_FUNC_,__FILE__,(unsigned long)__LINE__)
#if _WIN32
#define xmem_set_output_function(a) xmem_set_output_function((a),_FUNC_,__FILE__,(unsigned long)__LINE__)
#endif
#define xmem_get_overhead()         xmem_get_overhead(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_enable_print()         xmem_enable_print(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_disable_print()        xmem_disable_print(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_enable_log()           xmem_enable_log(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_disable_log()          xmem_disable_log(_FUNC_,__FILE__,(unsigned long)__LINE__)
#define xmem_message(a)             xmem_message((a),_FUNC_,__FILE__,(unsigned long)__LINE__);
#define xmem_enter_scope()          xmem_enter_scope(_FUNC_,__FILE__,(unsigned long)__LINE__);
#define xmem_leave_scope()          xmem_leave_scope(_FUNC_,__FILE__,(unsigned long)__LINE__);

/******** mapping of BSD functions to standard C functions ********/
#ifdef bcopy
#undef bcopy
#endif
#define bcopy(src,dst,n)        memmove(dst,src,n)

#ifdef bzero
#undef bzero
#endif
#define bzero(ptr,n)            memset(ptr,0,n)

#ifdef bcmp
#undef bcmp
#endif
#define bcmp(ptr1,ptr2,n)       memcmp(ptr2,ptr1,n)

#ifdef __CYGWIN__
/******** mapping of CYGWIN string functions ********/
#ifdef stricmp
#undef stricmp
#endif
#ifdef strnicmp
#undef strnicmp
#endif
#ifdef strcmpi
#undef strcmpi
#endif

#endif          /* __CYGWIN__ */

/*****************************************************************/
/**** mapping of standard library functions to XMEM functions ****/
/*****************************************************************/
#define malloc(a)         xmem_malloc((a)       _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define calloc(a,b)       xmem_calloc((a),(b)   _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define realloc(a,b)      xmem_realloc((a),(b)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define xmalloc(a)        xmem_xmalloc((a)      _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define xcalloc(a,b)      xmem_xcalloc((a),(b)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define xrealloc(a,b)     xmem_xrealloc((a),(b) _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#if defined(_MSC_VER)
#define _expand(a,b)      xmem_expand((a),(b)   _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#endif

#if XMEM_ALLOCA
#define alloca(a)         xmem_alloca(os_alloca((size_t)(a) + xmem_get_overhead()), (size_t)(a) + xmem_get_overhead() _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#endif

#if XMEM_FREENULL         /* set freed pointer to NULL to force Access Violation (default) */
#define free(a)           xmem_free((a)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__)),(a)=NULL
#define cfree(a)          xmem_cfree((a) _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__)),(a)=NULL
#define xfree(a)          xmem_xfree((a) _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__)),(a)=NULL
#define FREENULL(a)       (a)=NULL
#else                     /* do not set freed pointer to NULL, keep old value */
#define free(a)           xmem_free((a)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define cfree(a)          xmem_cfree((a) _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define xfree(a)          xmem_xfree((a) _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define FREENULL(a)
#endif          /* XMEM_FREENULL */

#if XMEM_STR              /**** if tracing of strxx string functions enabled ****/
#define strcat(a,b)       xmem_strcat((a),(b)       _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strncat(a,b,c)    xmem_strncat((a),(b),(c)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strchr(a,b)       xmem_strchr((a),(b)       _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strcmp(a,b)       xmem_strcmp((a),(b)       _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strcmpi(a,b)      xmem_strcmpi((a),(b)      _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define _strcmpi(a,b)     xmem_strcmpi((a),(b)      _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strcpy(a,b)       xmem_strcpy((a),(b)       _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strdup(a)         xmem_strdup((a)           _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define _strdup(a)        xmem_strdup((a)           _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define stricmp(a,b)      xmem_stricmp((a),(b)      _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define _stricmp(a,b)     xmem_stricmp((a),(b)      _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strlen(a)         xmem_strlen((a)           _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strnlen(a,b)      xmem_strlen((a),(b)       _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#ifndef __linux__
#define strlwr(a)         xmem_strlwr((a)           _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define _strlwr(a)        xmem_strlwr((a)           _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#endif
#define strncmp(a,b,c)    xmem_strncmp((a),(b),(c)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#ifndef __linux__
#define strnicmp(a,b,c)   xmem_strnicmp((a),(b),(c) _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define _strnicmp(a,b,c)  xmem_strnicmp((a),(b),(c) _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#endif
#define strncpy(a,b,c)    xmem_strncpy((a),(b),(c)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strrchr(a,b)      xmem_strrchr((a),(b)      _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strrev(a)         xmem_strrev((a)           _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define _strrev(a)        xmem_strrev((a)           _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strset(a,b)       xmem_strset((a),(b)       _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define _strset(a,b)      xmem_strset((a),(b)       _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strnset(a,b,c)    xmem_strnset((a),(b),(c)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define _strnset(a,b,c)   xmem_strnset((a),(b),(c)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strstr(a,b)       xmem_strstr((a),(b)       _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define strtok(a,b)       xmem_strtok((a),(b)       _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#ifndef __linux__
#define strupr(a)         xmem_strupr((a)           _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define _strupr(a)        xmem_strupr((a)           _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#if !defined(XFILE) || (XFILE == 0)
#define gets(a)           xmem_gets((a)             _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#endif
#endif /* __linux__ */
#define vsprintf(a,b,c)   xmem_vsprintf((a),(b),(c) _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))

#if 0
/* NOTE: This "sprintf" macro replacement produces incorrect results due to return value! */
/* However, it is provided here for completeness and may be used at own risk */
#define sprintf           xmem_location(_FUNC_,__FILE__,(unsigned long)__LINE__),xmem_sprintf
#else
#define sprintf           xmem_sprintf
#endif

#endif          /* XMEM_STR */

#if XMEM_MEM              /**** if tracing of memxxx memory functions enabled ****/
#define memchr(a,b,c)     xmem_memchr((a),(b),(c)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define memcmp(a,b,c)     xmem_memcmp((a),(b),(c)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define memcpy(a,b,c)     xmem_memcpy((a),(b),(c)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define memicmp(a,b,c)    xmem_memicmp((a),(b),(c) _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define _memicmp(a,b,c)   xmem_memicmp((a),(b),(c) _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define memmove(a,b,c)    xmem_memmove((a),(b),(c) _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define memset(a,b,c)     xmem_memset((a),(b),(c)  _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#endif          /* XMEM_MEM */

#if XMEM_FILE             /**** if tracing of stream functions enabled ****/
#define fgets(a,b,c)      xmem_fgets((a),(b),(c)     _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#define fread(a,b,c,d)    xmem_fread((a),(b),(c),(d) _WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__))
#endif          /* XMEM_FILE */

/************************************************/
/******** C++ specific memory allocation ********/
/************************************************/
#ifdef __cplusplus      /******** if C++ compilation ********/
#if XMEM_CPP            /******** XMEM_CPP ********/
#if XMEM_WHERE          /******** XMEM_WHERE ********/

#if XMEM_CRITICAL_OPERATOR
void *operator new(size_t);
#endif
void *operator new(size_t _WHERE(const char *, const char *, unsigned long));
#if XMEM_NEWARRAY
 #if XMEM_CRITICAL_OPERATOR
 void *operator new[] (size_t);
 #endif
 void *operator new[] (size_t _WHERE(const char *, const char *, unsigned long));
#endif

/* carefully check if these macros work well, absolutely no guarantee, side effects may occur */
#define new         new _CPP_WHERE(_FUNC_,__FILE__,(unsigned long)__LINE__)

void operator delete(void *);
#if !(_MSC_VER == 800)
void operator delete(void * _WHERE(const char *, const char *, unsigned long));
#endif
#if XMEM_DELETEARRAY
 void operator delete[] (void *);
 #if !(_MSC_VER == 800)
 void operator delete[] (void * _WHERE(const char *, const char *, unsigned long));
 #endif
#endif

/* carefully check if these macros work well, absolutely no guarantee, side effects may occur */
#if XMEM_CPP_DELETE_STACK
 extern int xmem_delete_lock;
 /* complex C++ delete macro to catch nested operator delete calls, may cause problems with multi-threading */
 #define delete     for(xmem_delete_lock = 1; xmem_delete_lock; xmem_after_delete())  \
                      xmem_before_delete(_FUNC_,__FILE__,(unsigned long)__LINE__), xmem_delete_lock = 0, delete
#else
 /* simple C++ delete macro */
 #define delete     xmem_location(_FUNC_,__FILE__,(unsigned long)__LINE__),delete
#endif

#endif          /******** XMEM_WHERE ********/
#endif          /******** XMEM_CPP ********/
#endif          /******** if C++ compilation ********/

/*****************************************************************************/
#endif                  /**** ifndef __XMEM__ ****/
/*****************************************************************************/


/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
#else                   /**** if XMEM (-> disabled) ****/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/


/**** remove XMEM specific functions if XMEM disabled ****/
#define xmem_showstatus()                   0
#define xmem_check_free()                   0
#define xmem_check_free_virtual(a)          0
#define xmem_check_ptr(a)                   0
#define xmem_overwrite()                    0
#define xmem_location(a,b,c)                0
#define xmem_set_memtrace(a)                0
#define xmem_enable_memtrace()              0
#define xmem_disable_memtrace()             0
#define xmem_get_alloc_nr()                 0
#define xmem_set_trace_alloc(a)             0
#define xmem_reset_trace_alloc()            0
#define xmem_set_trace_free(a)              0
#define xmem_reset_trace_free()             0
#define xmem_set_max_heapsize(a)            0
#define xmem_get_max_heapsize()             0
#define xmem_set_stress_ratio(a)            0
#define xmem_get_stress_ratio()             0
#define xmem_set_output_function(a)         0
#define xmem_get_overhead()                 0
#define xmem_enable_print()                 0
#define xmem_disable_print()                0
#define xmem_enable_log()                   0
#define xmem_disable_log()                  0
#define xmem_message(a)                     0
#define xmem_enter_scope()                  0
#define xmem_leave_scope()                  0


/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
#endif                  /**** if XMEM ****/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/

#endif                  /**** ifndef __XMEM_H_INCLUDED__ ****/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -