mem.h revision 9c3531d72aeaad6c5f01efe6a1c82023e1379e4d
/*
* Copyright (C) 1997-2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/* $Id: mem.h,v 1.36 2000/06/22 21:57:46 tale Exp $ */
#ifndef ISC_MEM_H
#define ISC_MEM_H 1
#include <stdio.h>
typedef void * (*isc_memalloc_t)(void *, size_t);
typedef void (*isc_memfree_t)(void *, void *);
#define ISC_MEM_DEBUG
extern isc_boolean_t isc_mem_debugging;
#ifdef ISC_MEM_DEBUG
#define isc_mem_allocate(c, s) isc__mem_allocatedebug(c, s, \
#define isc_mem_strdup(c, p) isc__mem_strdupdebug(c, p, \
#define isc_mempool_put(c, p) isc__mempool_putdebug(c, p, \
#else
#define isc_mem_get isc__mem_get
#define isc_mem_put isc__mem_put
#define isc_mem_allocate isc__mem_allocate
#define isc_mem_free isc__mem_free
#define isc_mem_strdup isc__mem_strdup
#define isc_mempool_get isc__mempool_get
#define isc_mempool_put isc__mempool_put
#endif /* ISC_MEM_DEBUG */
void isc_mem_detach(isc_mem_t **);
void isc_mem_destroy(isc_mem_t **);
isc_event_t **event);
const char *, int);
void isc__mem_putdebug(isc_mem_t *, void *,
size_t, const char *, int);
const char *, int);
void isc__mem_free(isc_mem_t *, void *);
void isc__mem_freedebug(isc_mem_t *, void *,
const char *, int);
char * isc__mem_strdup(isc_mem_t *, const char *);
char * isc__mem_strdupdebug(isc_mem_t *,
const char *,
const char *, int);
void isc_mem_setdestroycheck(isc_mem_t *,
#ifdef ISC_MEMCLUSTER_LEGACY
/*
* Legacy.
*/
#define meminit isc__legacy_meminit
#ifdef MEMCLUSTER_DEBUG
#define memput(p, s) isc__legacy_memput_debug(p, s, \
#else
#define memget isc__legacy_memget
#define memput isc__legacy_memput
#endif
#define memvalid isc__legacy_memvalid
#define memstats isc__legacy_memstats
isc_mem_t * mem_default_context(void);
void * isc__legacy_memget(size_t);
void isc__legacy_memput(void *, size_t);
void * isc__legacy_memget_debug(size_t, const char *,
int);
void isc__legacy_memput_debug(void *, size_t,
const char *, int);
int memvalid(void *);
#endif /* ISC_MEMCLUSTER_LEGACY */
/*
* Memory pools
*/
/*
* Internal (but public) functions. Don't call these from application
* code. Use isc_mempool_get() and isc_mempool_put() instead.
*/
void * isc__mempool_get(isc_mempool_t *);
void isc__mempool_put(isc_mempool_t *, void *);
void * isc__mempool_getdebug(isc_mempool_t *, const char *, int);
void isc__mempool_putdebug(isc_mempool_t *, void *,
const char *, int);
/*
* Create a memory pool.
*
* Requires:
* mctx is a valid memory context.
* size > 0
* mpctxp != NULL and *mpctxp == NULL
*
* Defaults:
* maxalloc = UINT_MAX
* freemax = 1
* fillcount = 1
*
* Returns:
* ISC_R_NOMEMORY -- not enough memory to create pool
* ISC_R_SUCCESS -- all is well.
*/
void
/*
* Destroy a memory pool.
*
* Requires:
* mpctxp != NULL && *mpctxp is a valid pool.
* The pool has no un"put" allocations outstanding
*/
void
/*
* Associate a name with a memory pool. At most 15 characters may be used.
*
* Requires:
* mpctx is a valid pool.
* name != NULL;
*/
void
/*
* 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:
*
* mpctpx is a valid pool.
*
* lock != NULL.
*
* No previous lock is assigned to this pool.
*
* The lock is initialized before calling this function via the normal
* means of doing that.
*/
/*
* 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 int
/*
* Returns the maximum allowed size of the free list.
*/
void
/*
* Sets the maximum allowed size of the free list.
*/
unsigned int
/*
* Returns current size of the free list.
*/
unsigned int
/*
* Returns the maximum allowed number of allocations.
*/
void
/*
* Sets the maximum allowed number of allocations.
*
* Additional requirements:
* limit > 0
*/
unsigned int
/*
* Returns the number of items allocated from this pool.
*/
unsigned int
/*
* Returns the number of items allocated as a block from the parent memory
* context when the free list is empty.
*/
void
/*
* Sets the fillcount.
*
* Additional requirements:
* limit > 0
*/
#endif /* ISC_MEM_H */