File: pool.h

package info (click to toggle)
prayer 1.3.5-dfsg1-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,596 kB
  • sloc: ansic: 43,163; makefile: 817; sh: 445; perl: 166
file content (48 lines) | stat: -rw-r--r-- 1,800 bytes parent folder | download | duplicates (6)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* $Cambridge: hermes/src/prayer/lib/pool.h,v 1.3 2008/09/16 09:59:57 dpc22 Exp $ */

/************************************************
 *    Prayer - a Webmail Interface              *
 ************************************************/

/* Copyright (c) University of Cambridge 2000 - 2008 */
/* See the file NOTICE for conditions of use and distribution. */

/* Pool:
 *  Memory allocated in pools which can be freed as a single operation.
 *  Idea is to make memory management for transient data structures
 *  a bit easier. Does use more memory than direct malloc/free.
 *
 * Methods:
 *   pool_create (initialise pool data structure)
 *   pool_alloc  (allocate memory using nominated pool)
 *   pool_free   (free all memory allocated in this pool).
 */

/* Malloc pool in 4Kbyte chunks by default */
#define PREFERRED_POOL_BLOCK_SIZE  (4096)

struct pool_elt {
    struct pool_elt *next;      /* Linked list of data blocks */
    char data[1];
};

struct pool {
    struct pool_elt *first;     /* First data block */
    struct pool_elt *last;      /* Last data block */
    unsigned long blocksize;    /* Default block size for small allocations */
    unsigned long avail;        /* Available space in current (last) block */
    struct str *str_list;
};

struct pool *pool_create(unsigned long blocksize);
void pool_free(struct pool *p);
void *pool_alloc(struct pool *p, unsigned long size);
char *pool_strdup(struct pool *p, char *value);
char *pool_strcat(struct pool *p, char *s1, char *s2);
char *pool_strcat3(struct pool *p, char *s1, char *s2, char *s3);

unsigned long pool_vprintf_size(char *fmt, va_list ap);
void pool_vprintf(char *target, char *fmt, va_list ap);
char *pool_printf(struct pool *p, char *fmt, ...);

char *pool_join(struct pool *pool, char join_char, char *argv[]);