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

📄 dmalloc.h.3

📁 减少内存碎片的malloc分配函数
💻 3
📖 第 1 页 / 共 2 页
字号:
 * RETURNS: * * Success - DMALLOC_NOERROR * * Failure - DMALLOC_ERROR * * ARGUMENTS: * * pnt -> Pointer we are checking. * * user_size_p <- Pointer to a DMALLOC_SIZE type variable which, if * not NULL, will be set to the size of bytes from the pointer. * * total_size_p <- Poiner to a DMALLOC_SIZE type variable which, if * not NULL, will be set to the total size given for this allocation * including administrative overhead. * * file_p <- Pointer to a character pointer which, if not NULL, will * be set to the file where the pointer was allocated. * * line_p <- Pointer to an unsigned integer which, if not NULL, will * be set to the line-number where the pointer was allocated. * * ret_attr_p <- Pointer to a void pointer, if not NULL, will be set * to the return-address where the pointer was allocated. * * used_mark_p <- Poiner to an unsigned integer which, if not NULL, * will be set to the mark of when the pointer was last "used".  This * could be when it was allocated, reallocated, or freed. * * seen_p <- Poiner to an unsigned long which, if not NULL, will be * set to the number of times that this pointer has been allocated, * realloced, or freed. */externint	dmalloc_examine(const DMALLOC_PNT pnt, DMALLOC_SIZE *user_size_p,			DMALLOC_SIZE *total_size_p, char **file_p,			unsigned int *line_p, DMALLOC_PNT *ret_attr_p,			unsigned long *used_mark_p, unsigned long *seen_p);/* * void dmalloc_track * * DESCRIPTION: * * Register an allocation tracking function which will be called each * time an allocation occurs. * * RETURNS: * * None. * * ARGUMENTS: * * track_func -> Function to register as the tracking function.  Set * to NULL to disable. */externvoid	dmalloc_track(const dmalloc_track_t track_func);/* * unsigned long dmalloc_mark * * DESCRIPTION: * * Return to the caller the current "mark" which can be used later by * dmalloc_log_changed to log the changed pointers since this point. * Multiple marks can be saved and used. * * This is also the iteration number and can be logged at the front of * each memory transaction in the logfile with the LOG_ITERATION * define in settings.h and can be logged with each pointer with the * LOG_PNT_ITERATION define in settings.h. * * RETURNS: * * Current mark value * * ARGUMENTS: * * None. */externunsigned long	dmalloc_mark(void);/* * unsigned long dmalloc_memory_allocated * * DESCRIPTION: * * Return the total number of bytes allocated by the program so far. * * RETURNS: * * Total number of bytes allocated by the program so far. * * ARGUMENTS: * * None. */externunsigned long	dmalloc_memory_allocated(void);/* * unsigned int dmalloc_page_size * * DESCRIPTION: * * Get the page-size being used by dmalloc. * * RETURNS: * * Page size. * * ARGUMENTS: * * None. */externunsigned int	dmalloc_page_size(void);/* * unsigned long dmalloc_count_changed * * DESCRIPTION: * * Count the changed memory bytes since a particular mark. * * RETURNS: * * Number of bytes since mark. * * ARGUMENTS: * * mark -> Sets the point from which to count the changed memory.  You * can use dmalloc_mark to get the current mark value which can later * be passed in here.  Pass in 0 to report on the unfreed memory since * the program started. * * not_freed_b -> Set to 1 to count the new pointers that are non-freed. * * free_b -> Set to 1 to count the new pointers that are freed. */externunsigned long	dmalloc_count_changed(const unsigned long mark,				      const int not_freed_b, const int free_b);/* * void dmalloc_log_status * * DESCRIPTION: * * Dump dmalloc statistics to logfile. * * RETURNS: * * None. * * ARGUMENTS: * * None. */externvoid	dmalloc_log_stats(void);/* * void dmalloc_log_unfreed * * DESCRIPTION: * * Dump unfreed-memory info to logfile. * * RETURNS: * * None. * * ARGUMENTS: * * None. */externvoid	dmalloc_log_unfreed(void);/* * void dmalloc_log_changed * * DESCRIPTION: * * Dump the pointers that have changed since a point in time. * * RETURNS: * * mark -> Sets the point to compare against.  You can use * dmalloc_mark to get the current mark value which can later be * passed in here.  Pass in 0 to log what has changed since the * program started. * * not_freed_b -> Set to 1 to log the new pointers that are non-freed. * * free_b -> Set to 1 to log the new pointers that are freed. * * details_b -> Set to 1 to dump the individual pointers that have * changed otherwise the summaries will be logged. */externvoid	dmalloc_log_changed(const unsigned long mark, const int not_freed_b,			    const int free_b, const int details_b);/* * void dmalloc_vmessage * * DESCRIPTION: * * Message writer with vprintf like arguments which adds a line to the * dmalloc logfile. * * RETURNS: * * None. * * ARGUMENTS: * * format -> Printf-style format statement. * * args -> Already converted pointer to a stdarg list. */externvoid	dmalloc_vmessage(const char *format, va_list args);/* * void dmalloc_message * * DESCRIPTION: * * Message writer with printf like arguments which adds a line to the * dmalloc logfile. * * RETURNS: * * None. * * ARGUMENTS: * * format -> Printf-style format statement. * * ... -> Variable argument list. */externvoid	dmalloc_message(const char *format, ...)#ifdef __GNUC__  __attribute__ ((format (printf, 1, 2)))#endif;/* * const char *dmalloc_strerror * * DESCRIPTION: * * Convert a dmalloc error code into its string equivalent. * * RETURNS: * * Success - String version of the error * * Failure - The string "unknown error" * * ARGUMENTS: * * error_num -> Error number we are converting. */externconst char	*dmalloc_strerror(const int error_num);#ifdef __cplusplus}#endif/* * alloc macros to provide for memory FILE/LINE debugging information. */#ifndef DMALLOC_DISABLE#undef malloc#define malloc(size) \  dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_MALLOC, 0, 0)#undef calloc#define calloc(count, size) \  dmalloc_malloc(__FILE__, __LINE__, (count)*(size), DMALLOC_FUNC_CALLOC, 0, 0)#undef realloc#define realloc(ptr, size) \  dmalloc_realloc(__FILE__, __LINE__, (ptr), (size), DMALLOC_FUNC_REALLOC, 0)#undef recalloc#define recalloc(ptr, size) \  dmalloc_realloc(__FILE__, __LINE__, (ptr), (size), DMALLOC_FUNC_RECALLOC, 0)#undef memalign#define memalign(alignment, size) \  dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_MEMALIGN, \		 (alignment), 0 /* no xalloc */)#undef valloc#define valloc(size) \  dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_VALLOC, \		0 /* special case */, 0 /* no xalloc */)#ifndef DMALLOC_STRDUP_MACRO#undef strdup#define strdup(str) \  dmalloc_strdup(__FILE__, __LINE__, (str), 0)#endif#undef free#define free(ptr) \  dmalloc_free(__FILE__, __LINE__, (ptr), DMALLOC_FUNC_FREE)#undef xmalloc#define xmalloc(size) \  dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_MALLOC, 0, 1)#undef xcalloc#define xcalloc(count, size) \  dmalloc_malloc(__FILE__, __LINE__, (count)*(size), DMALLOC_FUNC_CALLOC, 0, 1)#undef xrealloc#define xrealloc(ptr, size) \  dmalloc_realloc(__FILE__, __LINE__, (ptr), (size), DMALLOC_FUNC_REALLOC, 1)#undef xrecalloc#define xrecalloc(ptr, size) \  dmalloc_realloc(__FILE__, __LINE__, (ptr), (size), DMALLOC_FUNC_RECALLOC, 1)#undef xmemalign#define xmemalign(alignment, size) \  dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_MEMALIGN, \		 (alignment), 1)#undef xvalloc#define xvalloc(size) \  dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_VALLOC, 0, 1)#undef xstrdup#define xstrdup(str) \  dmalloc_strdup(__FILE__, __LINE__, (str), 1)#undef xfree#define xfree(ptr) \  dmalloc_free(__FILE__, __LINE__, (ptr), DMALLOC_FUNC_FREE)#ifdef DMALLOC_FUNC_CHECK/* * do debugging on the following functions.  this may cause compilation or * other problems depending on your architecture. */#undef bcmp#define bcmp(b1, b2, len)		_dmalloc_bcmp((b1), (b2), (len))#undef bcopy#define bcopy(from, to, len)		_dmalloc_bcopy((from), (to), (len))#undef memcmp#define memcmp(b1, b2, len)		_dmalloc_memcmp((b1), (b2), (len))#undef memcpy#define memcpy(to, from, len)		_dmalloc_memcpy((to), (from), (len))#undef memset#define memset(buf, ch, len)		_dmalloc_memset((buf), (ch), (len))#undef index#define index(str, ch)			_dmalloc_index((str), (ch))#undef rindex#define rindex(str, ch)			_dmalloc_rindex((str), (ch))#undef strcat#define strcat(to, from)		_dmalloc_strcat((to), (from))#undef strcmp#define strcmp(s1, s2)			_dmalloc_strcmp((s1), (s2))#undef strlen#define strlen(str)			_dmalloc_strlen((str))#undef strtok#define strtok(str, sep)		_dmalloc_strtok((str), (sep))#undef bzero#define bzero(buf, len)			_dmalloc_bzero((buf), (len))#undef memccpy#define memccpy(s1, s2, ch, len)	_dmalloc_memccpy((s1), (s2),(ch),(len))#undef memchr#define memchr(s1, ch, len)		_dmalloc_memchr((s1), (ch), (len))#undef strchr#define strchr(str, ch)			_dmalloc_strchr((str), (ch))#undef strrchr#define strrchr(str, ch)		_dmalloc_strrchr((str), (ch))#undef strcpy#define strcpy(to, from)		_dmalloc_strcpy((to), (from))#undef strncpy#define strncpy(to, from, len)		_dmalloc_strncpy((to), (from), (len))#undef strcasecmp#define strcasecmp(s1, s2)		_dmalloc_strcasecmp((s1), (s2))#undef strncasecmp#define strncasecmp(s1, s2, len)	_dmalloc_strncasecmp((s1), (s2), (len))#undef strspn#define strspn(str, list)		_dmalloc_strspn((str), (list))#undef strcspn#define strcspn(str, list)		_dmalloc_strcspn((str), (list))#undef strncat#define strncat(to, from, len)		_dmalloc_strncat((to), (from), (len))#undef strncmp#define strncmp(s1, s2, len)		_dmalloc_strncmp((s1), (s2), (len))#undef strpbrk#define strpbrk(str, list)		_dmalloc_strpbrk((str), (list))#undef strstr#define strstr(str, pat)		_dmalloc_strstr((str), (pat))#endif /* DMALLOC_FUNC_CHECK */#endif /* ! DMALLOC_DISABLE *//* * feel free to add your favorite functions here and to arg_check.[ch] */#ifdef __cplusplusextern "C" {#endif/* * Dummy function for checking atoi's arguments. */externint	_dmalloc_atoi(const char *str);/* * Dummy function for checking atol's arguments. */externlong	_dmalloc_atol(const char *str);/* * Dummy function for checking bcmp's arguments. */externint	_dmalloc_bcmp(const void *b1, const void *b2, const DMALLOC_SIZE len);/* * Dummy function for checking bcopy's arguments. */externvoid	_dmalloc_bcopy(const void *from, void *to, const DMALLOC_SIZE len);/* * Dummy function for checking bzero's arguments. */externvoid	_dmalloc_bzero(void *buf, const DMALLOC_SIZE len);/* * Dummy function for checking index's arguments. */externchar	*_dmalloc_index(const char *str, const char ch);/* * Dummy function for checking memccpy's arguments. */externvoid	*_dmalloc_memccpy(void *s1, const void *s2, const int ch,			  const DMALLOC_SIZE len);/* * Dummy function for checking memchr's arguments. */externvoid	*_dmalloc_memchr(const void *s1, const int ch, const DMALLOC_SIZE len);/* * Dummy function for checking memcmp's arguments. */externint	_dmalloc_memcmp(const void *b1, const void *b2, const DMALLOC_SIZE len);/* * Dummy function for checking memcpy's arguments. */externvoid	*_dmalloc_memcpy(void *to, const void *from, const DMALLOC_SIZE len);/* * Dummy function for checking memcpy's arguments. */externvoid	*_dmalloc_memmove(void *to, const void *from, const DMALLOC_SIZE len);/* * Dummy function for checking memset's arguments. */externvoid	*_dmalloc_memset(void *buf, const int ch, const DMALLOC_SIZE len);/* * Dummy function for checking rindex's arguments. */externchar	*_dmalloc_rindex(const char *str, const char ch);/* * Dummy function for checking strcasecmp's arguments. */externint	_dmalloc_strcasecmp(const char *s1, const char *s2);/* * Dummy function for checking strcat's arguments. */externchar	*_dmalloc_strcat(char *to, const char *from);/* * Dummy function for checking strchr's arguments. */externchar	*_dmalloc_strchr(const char *str, const int ch);/* * Dummy function for checking strcmp's arguments. */externint	_dmalloc_strcmp(const char *s1, const char *s2);/* * Dummy function for checking strcpy's arguments. */externchar	*_dmalloc_strcpy(char *to, const char *from);/* * Dummy function for checking strcspn's arguments. */externint	_dmalloc_strcspn(const char *str, const char *list);/* * Dummy function for checking strlen's arguments. */externDMALLOC_SIZE	_dmalloc_strlen(const char *str);/* * Dummy function for checking strncasecmp's arguments. */externint	_dmalloc_strncasecmp(const char *s1, const char *s2,			     const DMALLOC_SIZE len);/* * Dummy function for checking strncat's arguments. */externchar	*_dmalloc_strncat(char *to, const char *from, const DMALLOC_SIZE len);/* * Dummy function for checking strncmp's arguments. */externint	_dmalloc_strncmp(const char *s1, const char *s2,			 const DMALLOC_SIZE len);/* * Dummy function for checking strncpy's arguments. */externchar	*_dmalloc_strncpy(char *to, const char *from, const DMALLOC_SIZE len);/* * Dummy function for checking strpbrk's arguments. */externchar	*_dmalloc_strpbrk(const char *str, const char *list);/* * Dummy function for checking strrchr's arguments. */externchar	*_dmalloc_strrchr(const char *str, const int ch);/* * Dummy function for checking strspn's arguments. */externint	_dmalloc_strspn(const char *str, const char *list);/* * Dummy function for checking strstr's arguments. */externchar	*_dmalloc_strstr(const char *str, const char *pat);/* * Dummy function for checking strtok's arguments. */externchar	*_dmalloc_strtok(char *str, const char *sep);#ifdef __cplusplus}#endif#endif /* ! __DMALLOC_H__ */

⌨️ 快捷键说明

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