#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 */
};

void mp_init(struct mempool *mp);
void *mp_alloc(struct mempool *mp, unsigned size);
void mp_free(struct mempool *mp);
char *mp_strdup(struct mempool *mp, const char *str);

struct strpool { /* string pool */
  struct mempool sp_mp;
  const char *sp_last; /* last allocated string */
};

void sp_init(struct strpool *sp);
void sp_free(struct strpool *sp);
const char *sp_strdup(struct strpool *sp, const char *str);
/* reuse strings */

#endif
