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

📄 dmalloc.h.3

📁 减少内存碎片的malloc分配函数
💻 3
📖 第 1 页 / 共 2 页
字号:
/* NOTE: start of $Id: dmalloc.h.4,v 1.10 2004/10/19 14:50:52 gray Exp $ *//* dmalloc version defines */#define DMALLOC_VERSION_MAJOR	5	/* X.0.0 */#define DMALLOC_VERSION_MINOR	4	/* 0.X.0 */#define DMALLOC_VERSION_PATCH	2	/* 0.0.X *//* this defines what type the standard void memory-pointer is */#if (defined(__STDC__) && __STDC__ == 1) || defined(__cplusplus) || defined(STDC_HEADERS)#define DMALLOC_PNT		void *#define DMALLOC_FREE_RET	void#else#define DMALLOC_PNT		char *#define DMALLOC_FREE_RET	int#endif/* * Malloc function return codes */#define CALLOC_ERROR		0L		/* error from calloc */#define MALLOC_ERROR		0L		/* error from malloc */#define REALLOC_ERROR		0L		/* error from realloc *//* NOTE: this if for non- __STDC__ systems only */#define FREE_ERROR		0		/* error from free */#define FREE_NOERROR		1		/* no error from free */#define DMALLOC_ERROR		0		/* function failed */#define DMALLOC_NOERROR		1		/* function succeeded */#define DMALLOC_VERIFY_ERROR	0		/* function failed */#define DMALLOC_VERIFY_NOERROR	1		/* function succeeded */#define MALLOC_VERIFY_ERROR	DMALLOC_VERIFY_ERROR#define MALLOC_VERIFY_NOERROR	DMALLOC_VERIFY_NOERROR/* * Dmalloc function IDs for the dmalloc_track_t callback function. */#define DMALLOC_FUNC_MALLOC	10	/* malloc function called */#define DMALLOC_FUNC_CALLOC	11	/* calloc function called */#define DMALLOC_FUNC_REALLOC	12	/* realloc function called */#define DMALLOC_FUNC_RECALLOC	13	/* recalloc called */#define DMALLOC_FUNC_MEMALIGN	14	/* memalign function called */#define DMALLOC_FUNC_VALLOC	15	/* valloc function called */#define DMALLOC_FUNC_STRDUP	16	/* strdup function called */#define DMALLOC_FUNC_FREE	17	/* free function called */#define DMALLOC_FUNC_CFREE	18	/* cfree function called */#define DMALLOC_FUNC_NEW	20	/* new function called */#define DMALLOC_FUNC_NEW_ARRAY	21	/* new[] function called */#define DMALLOC_FUNC_DELETE	22	/* delete function called */#define DMALLOC_FUNC_DELETE_ARRAY 23	/* delete[] function called */#ifdef __cplusplusextern "C" {#endiftypedef void  (*dmalloc_track_t)(const char *file, const unsigned int line,				 const int func_id,				 const DMALLOC_SIZE byte_size,				 const DMALLOC_SIZE alignment,				 const DMALLOC_PNT old_addr,				 const DMALLOC_PNT new_addr);/* internal dmalloc error number for reference purposes only */externint		dmalloc_errno;/* logfile for dumping dmalloc info, DMALLOC_LOGFILE env var overrides this */externchar		*dmalloc_logpath;/* * void dmalloc_shutdown * * DESCRIPTION: * * Shutdown the dmalloc library and provide statistics if necessary. * * RETURNS: * * None. * * ARGUMENTS: * * None. */externvoid	dmalloc_shutdown(void);#if FINI_DMALLOC/* * void __fini_dmalloc * * DESCRIPTION: * * Automatic function to close dmalloc supported by some operating * systems.  Pretty cool OS/compiler hack.  By default it is not * necessary because we use atexit() and on_exit() to register the * close functions which are more portable. * * RETURNS: * * None. * * ARGUMENTS: * * None. */externvoid	__fini_dmalloc(void);#endif /* if FINI_DMALLOC *//* * DMALLOC_PNT dmalloc_malloc * * DESCRIPTION: * * Allocate and return a memory block of a certain size. * * RETURNS: * * Success - Valid pointer. * * Failure - 0L * * ARGUMENTS: * * file -> File-name or return-address of the caller. * * line -> Line-number of the caller. * * size -> Number of bytes requested. * * func_id -> Function-id to identify the type of call.  See * dmalloc.h. * * alignment -> To align the new block to a certain number of bytes, * set this to a value greater than 0. * * xalloc_b -> If set to 1 then print an error and exit if we run out * of memory. */externDMALLOC_PNT	dmalloc_malloc(const char *file, const int line,			       const DMALLOC_SIZE size, const int func_id,			       const DMALLOC_SIZE alignment,			       const int xalloc_b);/* * DMALLOC_PNT dmalloc_realloc * * DESCRIPTION: * * Resizes and old pointer to a new number of bytes. * * RETURNS: * * Success - Valid pointer. * * Failure - 0L * * ARGUMENTS: * * file -> File-name or return-address of the caller. * * line -> Line-number of the caller. * * old_pnt -> Pointer to an existing memory chunk that we are * resizing.  If this is NULL then it basically does a malloc. * * new_size -> New number of bytes requested for the old pointer. * * func_id -> Function-id to identify the type of call.  See * dmalloc.h. * * xalloc_b -> If set to 1 then print an error and exit if we run out * of memory. */externDMALLOC_PNT	dmalloc_realloc(const char *file, const int line,				DMALLOC_PNT old_pnt, DMALLOC_SIZE new_size,				const int func_id, const int xalloc_b);/* * int dmalloc_free * * DESCRIPTION: * * Release a pointer back into the heap. * * RETURNS: * * Success - FREE_NOERROR * * Failure - FREE_ERROR * * Note: many operating systems define free to return (void) so this * return value may be filtered.  Dumb. * * ARGUMENTS: * * file -> File-name or return-address of the caller. * * line -> Line-number of the caller. * * pnt -> Existing pointer we are freeing. * * func_id -> Function-id to identify the type of call.  See * dmalloc.h. */externint	dmalloc_free(const char *file, const int line, DMALLOC_PNT pnt,		     const int func_id);/* * DMALLOC_PNT dmalloc_strdup * * DESCRIPTION: * * Allocate and return an allocated block of memory holding a copy of * a string. * * RETURNS: * * Success - Valid pointer. * * Failure - 0L * * ARGUMENTS: * * file -> File-name or return-address of the caller. * * line -> Line-number of the caller. * * string -> String we are duplicating. * * xalloc_b -> If set to 1 then print an error and exit if we run out * of memory. */externchar	*dmalloc_strdup(const char *file, const int line,			const char *string, const int xalloc_b);/* * DMALLOC_PNT malloc * * DESCRIPTION: * * Overloading the malloc(3) function.  Allocate and return a memory * block of a certain size. * * RETURNS: * * Success - Valid pointer. * * Failure - 0L * * ARGUMENTS: * * size -> Number of bytes requested. */externDMALLOC_PNT	malloc(DMALLOC_SIZE size);/* * DMALLOC_PNT malloc * * DESCRIPTION: * * Overloading the calloc(3) function.  Returns a block of zeroed memory. * * RETURNS: * * Success - Valid pointer. * * Failure - 0L * * ARGUMENTS: * * num_elements -> Number of elements being allocated. * * size -> The number of bytes in each element. */externDMALLOC_PNT	calloc(DMALLOC_SIZE num_elements, DMALLOC_SIZE size);/* * DMALLOC_PNT realloc * * DESCRIPTION: * * Overload of realloc(3).  Resizes and old pointer to a new number of * bytes. * * RETURNS: * * Success - Valid pointer. * * Failure - 0L * * ARGUMENTS: * * old_pnt -> Pointer to an existing memory chunk that we are * resizing.  If this is NULL then it basically does a malloc. * * new_size -> New number of bytes requested for the old pointer. */externDMALLOC_PNT	realloc(DMALLOC_PNT old_pnt, DMALLOC_SIZE new_size);/* * DMALLOC_PNT recalloc * * DESCRIPTION: * * Overload of recalloc(3) which exists on some systems.  Resizes and * old pointer to a new number of bytes.  If we are expanding, then * any new bytes will be zeroed. * * RETURNS: * * Success - Valid pointer. * * Failure - 0L * * ARGUMENTS: * * old_pnt -> Pointer to an existing memory chunk that we are * resizing. * * new_size -> New number of bytes requested for the old pointer. */externDMALLOC_PNT	recalloc(DMALLOC_PNT old_pnt, DMALLOC_SIZE new_size);/* * DMALLOC_PNT memalign * * DESCRIPTION: * * Overloading the memalign(3) function.  Allocate and return a memory * block of a certain size which have been aligned to a certain * alignment. * * RETURNS: * * Success - Valid pointer. * * Failure - 0L * * ARGUMENTS: * * alignment -> Value to which the allocation must be aligned.  This * should probably be a multiple of 2 with a maximum value equivalent * to the block-size which is often 1k or 4k. * * size -> Number of bytes requested. */externDMALLOC_PNT	memalign(DMALLOC_SIZE alignment, DMALLOC_SIZE size);/* * DMALLOC_PNT valloc * * DESCRIPTION: * * Overloading the valloc(3) function.  Allocate and return a memory * block of a certain size which have been aligned to page boundaries * which are often 1k or 4k. * * RETURNS: * * Success - Valid pointer. * * Failure - 0L * * ARGUMENTS: * * size -> Number of bytes requested. */externDMALLOC_PNT	valloc(DMALLOC_SIZE size);#ifndef DMALLOC_STRDUP_MACRO/* * DMALLOC_PNT strdup * * DESCRIPTION: * * Overload of strdup(3).  Allocate and return an allocated block of * memory holding a copy of a string. * * RETURNS: * * Success - Valid pointer. * * Failure - 0L * * ARGUMENTS: * * string -> String we are duplicating. */externchar	*strdup(const char *string);#endif /* ifndef DMALLOC_STRDUP_MACRO *//* * DMALLOC_FREE_RET free * * DESCRIPTION: * * Release a pointer back into the heap. * * RETURNS: * * Returns FREE_ERROR, FREE_NOERROR or void depending on whether STDC * is defined by your compiler. * * ARGUMENTS: * * pnt -> Existing pointer we are freeing. */externDMALLOC_FREE_RET	free(DMALLOC_PNT pnt);/* * DMALLOC_FREE_RET cfree * * DESCRIPTION: * * Same as free. * * RETURNS: * * Returns FREE_ERROR, FREE_NOERROR or void depending on whether STDC * is defined by your compiler. * * ARGUMENTS: * * pnt -> Existing pointer we are freeing. */externDMALLOC_FREE_RET	cfree(DMALLOC_PNT pnt);/* * int dmalloc_verify * * DESCRIPTION: * * Verify a pointer which has previously been allocated by the * library or check the entire heap. * * RETURNS: * * Success - MALLOC_VERIFY_NOERROR * * Failure - MALLOC_VERIFY_ERROR * * ARGUMENTS: * * pnt -> Pointer we are verifying.  If 0L then check the entire heap. */externint	dmalloc_verify(const DMALLOC_PNT pnt);/* * int malloc_verify * * DESCRIPTION: * * Verify a pointer which has previously been allocated by the * library.  Same as dmalloc_verify. * * RETURNS: * * Success - MALLOC_VERIFY_NOERROR * * Failure - MALLOC_VERIFY_ERROR * * ARGUMENTS: * * pnt -> Pointer we are verifying.  If 0L then check the entire heap. */externint	malloc_verify(const DMALLOC_PNT pnt);/* * int dmalloc_verify_pnt * * DESCRIPTION: * * This function is mainly used by the arg_check.c functions to verify * specific pointers.  This can be used by users to provide more fine * grained tests on pointers. * * RETURNS: * * Success - MALLOC_VERIFY_NOERROR * * Failure - MALLOC_VERIFY_ERROR * * ARGUMENTS: * * file -> File-name or return-address of the caller.  You can use * __FILE__ for this argument or 0L for none. * * line -> Line-number of the caller.  You can use __LINE__ for this * argument or 0 for none. * * func -> Function string which is checking the pointer.  0L if none. * * pnt -> Pointer we are checking. * * exact_b -> Set to 1 if this pointer was definitely handed back from * a memory allocation.  If set to 0 then this pointer can be inside * another allocation or outside the heap altogether. * * min_size -> Make sure that pointer can hold at least that many * bytes if inside of the heap.  If -1 then make sure it can handle * strlen(pnt) + 1 bytes (+1 for the \0).  If 0 then don't check the * size. */externint	dmalloc_verify_pnt(const char *file, const int line, const char *func,			   const void *pnt, const int exact_b,			   const int min_size);/* * unsigned int dmalloc_debug * * DESCRIPTION: * * Set the global debug functionality flags.  You can also use * dmalloc_debug_setup. * * Note: you cannot add or remove certain flags such as signal * handlers since they are setup at initialization time only. * * RETURNS: * * The old debug flag value. * * ARGUMENTS: * * flags -> Flag value to set.  Pass in 0 to disable all debugging. */externunsigned int	dmalloc_debug(const unsigned int flags);/* * unsigned int dmalloc_debug_current * * DESCRIPTION: * * Returns the current debug functionality flags.  This allows you to * save a dmalloc library state to be restored later. * * RETURNS: * * Current debug flags. * * ARGUMENTS: * * None. */externunsigned int	dmalloc_debug_current(void);/* * void dmalloc_debug_setup * * DESCRIPTION: * * Set the global debugging functionality as an option string. * Normally this would be pased in in the DMALLOC_OPTIONS * environmental variable.  This is here to override the env or for * circumstances where modifying the environment is not possible or * does not apply such as servers or cgi-bin programs. * * RETURNS: * * None. * * ARGUMENTS: * * options_str -> Options string to set the library flags. */externvoid	dmalloc_debug_setup(const char *options_str);/* * int dmalloc_examine * * DESCRIPTION: * * Examine a pointer and pass back information on its allocation size * as well as the file and line-number where it was allocated.  If the * file and line number is not available, then it will pass back the * allocation location's return-address if available. *

⌨️ 快捷键说明

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