mem.h revision 453f3213e9d66257ae353e41d4c2c97dfcaa88ab
/*
* Copyright (C) 1997, 1998, 1999 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.
*/
#ifndef ISC_MEM_H
#define ISC_MEM_H 1
#include <stdio.h>
#include <stddef.h>
#ifdef ISC_MEM_DEBUG
#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_mempool_get __isc_mempool_get
#define isc_mempool_put __isc_mempool_put
#endif /* ISC_MEM_DEBUG */
void isc_mem_destroy(isc_mem_t **);
const char *, int);
void __isc_mem_putdebug(isc_mem_t *, void *,
size_t, const char *, int);
void isc_mem_free(isc_mem_t *, void *);
char * isc_mem_strdup(isc_mem_t *, const char *);
#ifdef ISC_MEMCLUSTER_LEGACY
/*
* Legacy.
*/
#ifdef MEMCLUSTER_DEBUG
#else
#endif
#define memvalid __memvalid
#define memstats __memstats
isc_mem_t * mem_default_context(void);
void * __memget_debug(size_t, const char *, int);
void __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);
isc_mempool_t **mpctxp);
/*
* 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.
*/
/*
* Destroy a memory pool.
*
* Requires:
* mpctxp is a valid pool.
* The pool has no un"put" allocations outstanding
*/
/*
* 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 larger 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
*/
/*
* Returns the maximum allowed size of the free list.
*/
unsigned int limit);
/*
* Sets the maximum allowed size of the free list.
*/
/*
* Returns current size of the free list.
*/
/*
* Returns the maximum allowed number of allocations.
*/
unsigned int limit);
/*
* Sets the maximum allowed number of allocations.
*
* Additional requirements:
* limit > 0
*/
/*
* Returns the number of items allocated from this pool.
*/
/*
* Returns the number of items allocated as a block from the parent memory
* context when the free list is empty.
*/
unsigned int limit);
/*
* Sets the fillcount.
*
* Additional requirements:
* limit > 0
*/
#endif /* MEM_H */