Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / libedataserver / e-memory.h
1 /*
2  * Copyright (C) 2001, Ximian Inc.
3  *
4  * Authors: Michael Zucchi <notzed@ximian.com>
5  *          Jacob Berkman <jacob@ximian.com>
6  *
7  * This program is free software; you can redistribute it and/or 
8  * modify it under the terms of version 2 of the GNU Lesser General Public 
9  * License as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19  * USA
20  */
21
22 #ifndef _E_MEMORY_H
23 #define _E_MEMORY_H
24
25 #include <glib.h>
26
27 G_BEGIN_DECLS
28
29 /* memchunks - allocate/free fixed-size blocks of memory */
30 /* this is like gmemchunk, only faster and less overhead (only 4 bytes for every atomcount allocations) */
31 typedef struct _EMemChunk EMemChunk;
32
33 EMemChunk *e_memchunk_new(int atomcount, int atomsize);
34 void *e_memchunk_alloc(EMemChunk *m);
35 void *e_memchunk_alloc0(EMemChunk *m);
36 void e_memchunk_free(EMemChunk *m, void *mem);
37 void e_memchunk_empty(EMemChunk *m);
38 void e_memchunk_clean(EMemChunk *m);
39 void e_memchunk_destroy(EMemChunk *m);
40
41 /* mempools - allocate variable sized blocks of memory, and free as one */
42 /* allocation is very fast, but cannot be freed individually */
43 typedef struct _EMemPool EMemPool;
44 typedef enum {
45         E_MEMPOOL_ALIGN_STRUCT = 0,     /* allocate to native structure alignment */
46         E_MEMPOOL_ALIGN_WORD = 1,       /* allocate to words - 16 bit alignment */
47         E_MEMPOOL_ALIGN_BYTE = 2,       /* allocate to bytes - 8 bit alignment */
48         E_MEMPOOL_ALIGN_MASK = 3, /* which bits determine the alignment information */
49 } EMemPoolFlags;
50
51 EMemPool *e_mempool_new(int blocksize, int threshold, EMemPoolFlags flags);
52 void *e_mempool_alloc(EMemPool *pool, int size);
53 char *e_mempool_strdup(EMemPool *pool, const char *str);
54 void e_mempool_flush(EMemPool *pool, int freeall);
55 void e_mempool_destroy(EMemPool *pool);
56
57 /* strv's string arrays that can be efficiently modified and then compressed mainly for retrival */
58 /* building is relatively fast, once compressed it takes the minimum amount of memory possible to store */
59 typedef struct _EStrv EStrv;
60
61 EStrv *e_strv_new(int size);
62 EStrv *e_strv_set_ref(EStrv *strv, int index, char *str);
63 EStrv *e_strv_set_ref_free(EStrv *strv, int index, char *str);
64 EStrv *e_strv_set(EStrv *strv, int index, const char *str);
65 EStrv *e_strv_pack(EStrv *strv);
66 char *e_strv_get(EStrv *strv, int index);
67 void e_strv_destroy(EStrv *strv);
68
69 /* poolv's are similar to strv's, but they store common strings */
70 typedef struct _EPoolv EPoolv;
71
72 EPoolv *e_poolv_new(unsigned int size);
73 EPoolv *e_poolv_cpy(EPoolv *dest, const EPoolv *src);
74 EPoolv *e_poolv_set(EPoolv *poolv, int index, char *str, int freeit);
75 const char *e_poolv_get(EPoolv *poolv, int index);
76 void e_poolv_destroy(EPoolv *poolv);
77
78 G_END_DECLS
79
80 #endif /* ! _E_MEMORY_H */