File: mempool.h

package info (click to toggle)
rbldnsd 0.996a-0.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 468 kB
  • ctags: 799
  • sloc: ansic: 5,704; sh: 349; makefile: 183; awk: 33
file content (29 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* $Id: mempool.h,v 1.7 2006/06/12 22:00:38 mjt Exp $
 * memory pool #include file
 */

#ifndef _MEMPOOL_H_INCLUDED
#define _MEMPOOL_H_INCLUDED

struct mempool_chunk;

struct mempool { /* free-once memory pool.  All members are private */
  struct mempool_chunk *mp_chunk; /* list of chunks with free space */
  struct mempool_chunk *mp_fullc; /* list of full chunks */
  unsigned mp_nallocs;		/* number of allocs so far */
  unsigned mp_datasz;		/* size of allocated data */
  const char *mp_lastbuf;	/* last allocated string */
  unsigned mp_lastlen;		/* length of lastbuf */
};

void mp_init(struct mempool *mp);
void *mp_alloc(struct mempool *mp, unsigned size, int align);
#define mp_talloc(mp, type) ((type*)mp_alloc((mp), sizeof(type), 1))
void mp_free(struct mempool *mp);
char *mp_strdup(struct mempool *mp, const char *str);
void *mp_memdup(struct mempool *mp, const void *buf, unsigned len);
const char *mp_dstrdup(struct mempool *mp, const char *str);
const void *mp_dmemdup(struct mempool *mp, const void *buf, unsigned len);
/* dstrdup, dmemdup trying to pack repeated strings together */

#endif