📄 mem.h
字号:
* in such a way that it is not obvious when the last allocations from * a given context has been freed and destroying the context is safe. * * Most applications do not need to call these functions as they can * simply create a single memory context at the beginning of main() * and destroy it at the end of main(), thereby guaranteeing that it * is not destroyed while there are outstanding allocations. *//*@}*/void isc_mem_destroy(isc_mem_t **);/*%< * Destroy a memory context. */isc_result_t isc_mem_ondestroy(isc_mem_t *ctx, isc_task_t *task, isc_event_t **event);/*%< * Request to be notified with an event when a memory context has * been successfully destroyed. */void isc_mem_stats(isc_mem_t *mctx, FILE *out);/*%< * Print memory usage statistics for 'mctx' on the stream 'out'. */void isc_mem_setdestroycheck(isc_mem_t *mctx, isc_boolean_t on);/*%< * If 'on' is ISC_TRUE, 'mctx' will check for memory leaks when * destroyed and abort the program if any are present. *//*@{*/void isc_mem_setquota(isc_mem_t *, size_t);size_t isc_mem_getquota(isc_mem_t *);/*%< * Set/get the memory quota of 'mctx'. This is a hard limit * on the amount of memory that may be allocated from mctx; * if it is exceeded, allocations will fail. *//*@}*/size_t isc_mem_inuse(isc_mem_t *mctx);/*%< * Get an estimate of the number of memory in use in 'mctx', in bytes. * This includes quantization overhead, but does not include memory * allocated from the system but not yet used. */voidisc_mem_setwater(isc_mem_t *mctx, isc_mem_water_t water, void *water_arg, size_t hiwater, size_t lowater);/*%< * Set high and low water marks for this memory context. * * When the memory * usage of 'mctx' exceeds 'hiwater', '(water)(water_arg, #ISC_MEM_HIWATER)' * will be called. When the usage drops below 'lowater', 'water' will * again be called, this time with #ISC_MEM_LOWATER. * * If 'water' is NULL then 'water_arg', 'hi_water' and 'lo_water' are * ignored and the state is reset. * * Requires: * * 'water' is not NULL. * hi_water >= lo_water */voidisc_mem_printactive(isc_mem_t *mctx, FILE *file);/*%< * Print to 'file' all active memory in 'mctx'. * * Requires ISC_MEM_DEBUGRECORD to have been set. */voidisc_mem_printallactive(FILE *file);/*%< * Print to 'file' all active memory in all contexts. * * Requires ISC_MEM_DEBUGRECORD to have been set. */voidisc_mem_checkdestroyed(FILE *file);/*%< * Check that all memory contexts have been destroyed. * Prints out those that have not been. * Fatally fails if there are still active contexts. *//* * Memory pools */isc_result_tisc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp);/*%< * Create a memory pool. * * Requires: *\li mctx is a valid memory context. *\li size > 0 *\li mpctxp != NULL and *mpctxp == NULL * * Defaults: *\li maxalloc = UINT_MAX *\li freemax = 1 *\li fillcount = 1 * * Returns: *\li #ISC_R_NOMEMORY -- not enough memory to create pool *\li #ISC_R_SUCCESS -- all is well. */voidisc_mempool_destroy(isc_mempool_t **mpctxp);/*%< * Destroy a memory pool. * * Requires: *\li mpctxp != NULL && *mpctxp is a valid pool. *\li The pool has no un"put" allocations outstanding */voidisc_mempool_setname(isc_mempool_t *mpctx, const char *name);/*%< * Associate a name with a memory pool. At most 15 characters may be used. * * Requires: *\li mpctx is a valid pool. *\li name != NULL; *//*voidisc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock);*//*%< * Associate a lock with this memory pool. * * This lock is used when getting or putting items using this memory pool, * and it is also used to set or get internal state via the isc_mempool_get*() * and isc_mempool_set*() set of functions. * * Mutiple pools can each share a single lock. For instance, if "manager" * type object contained pools for various sizes of events, and each of * these pools used a common lock. Note that this lock must NEVER be used * by other than mempool routines once it is given to a pool, since that can * easily cause double locking. * * Requires: * *\li mpctpx is a valid pool. * *\li lock != NULL. * *\li No previous lock is assigned to this pool. * *\li The lock is initialized before calling this function via the normal * means of doing that. *//* * The following functions get/set various parameters. Note that due to * the unlocked nature of pools these are potentially random values unless * the imposed externally provided locking protocols are followed. * * Also note that the quota limits will not always take immediate effect. * For instance, setting "maxalloc" to a number smaller than the currently * allocated count is permitted. New allocations will be refused until * the count drops below this threshold. * * All functions require (in addition to other requirements): * mpctx is a valid memory pool */unsigned intisc_mempool_getfreemax(isc_mempool_t *mpctx);/*%< * Returns the maximum allowed size of the free list. */voidisc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit);/*%< * Sets the maximum allowed size of the free list. */unsigned intisc_mempool_getfreecount(isc_mempool_t *mpctx);/*%< * Returns current size of the free list. */unsigned intisc_mempool_getmaxalloc(isc_mempool_t *mpctx);/*!< * Returns the maximum allowed number of allocations. */voidisc_mempool_setmaxalloc(isc_mempool_t *mpctx, unsigned int limit);/*%< * Sets the maximum allowed number of allocations. * * Additional requirements: *\li limit > 0 */unsigned intisc_mempool_getallocated(isc_mempool_t *mpctx);/*%< * Returns the number of items allocated from this pool. */unsigned intisc_mempool_getfillcount(isc_mempool_t *mpctx);/*%< * Returns the number of items allocated as a block from the parent memory * context when the free list is empty. */voidisc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit);/*%< * Sets the fillcount. * * Additional requirements: *\li limit > 0 *//* * Pseudo-private functions for use via macros. Do not call directly. */void * isc__mem_get(isc_mem_t *, size_t _ISC_MEM_FLARG);void isc__mem_putanddetach(isc_mem_t **, void *, size_t _ISC_MEM_FLARG);void isc__mem_put(isc_mem_t *, void *, size_t _ISC_MEM_FLARG);void * isc__mem_allocate(isc_mem_t *, size_t _ISC_MEM_FLARG);void isc__mem_free(isc_mem_t *, void * _ISC_MEM_FLARG);char * isc__mem_strdup(isc_mem_t *, const char *_ISC_MEM_FLARG);void * isc__mempool_get(isc_mempool_t * _ISC_MEM_FLARG);void isc__mempool_put(isc_mempool_t *, void * _ISC_MEM_FLARG);#ifdef HAVE_LIBXML2voidisc_mem_renderxml(isc_mem_t *mgr, xmlTextWriterPtr writer);#endif /* HAVE_LIBXML2 */ISC_LANG_ENDDECLS#endif /* ISC_MEM_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -