annotate src/lib/mempool-alloconly.c @ 3238:889a584bd953 HEAD

Changed alloconly pools to call malloc() only once when creating the pool. Pool names aren't used anymore without DEBUG. Don't immediately double the pool's initial size for the first allocated block.
author Timo Sirainen <tss@iki.fi>
date Sun, 27 Mar 2005 19:38:38 +0300
parents 6396b4c0a721
children 4cbb7b67bc98
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1741
9df02b1533b3 Removed most of the license comments from src/lib/*.c. It's just fine to
Timo Sirainen <tss@iki.fi>
parents: 1666
diff changeset
1 /* Copyright (c) 2002-2003 Timo Sirainen */
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
805
5ac361acb316 Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents: 699
diff changeset
3 /* @UNSAFE: whole file */
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "lib.h"
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "mempool.h"
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include <stdlib.h>
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8
1786
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
9 #ifdef HAVE_GC_GC_H
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
10 # include <gc/gc.h>
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
11 #elif defined (HAVE_GC_H)
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
12 # include <gc.h>
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
13 #endif
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
14
183
4a7ab9e94f25 size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents: 72
diff changeset
15 #define MAX_ALLOC_SIZE SSIZE_T_MAX
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
17 struct alloconly_pool {
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
18 struct pool pool;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 int refcount;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
21 size_t base_size;
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
22 struct pool_block *block;
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
23 #ifdef DEBUG
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
24 const char *name;
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
25 #endif
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
26 };
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
28 struct pool_block {
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
29 struct pool_block *prev;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30
183
4a7ab9e94f25 size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents: 72
diff changeset
31 size_t size;
4a7ab9e94f25 size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents: 72
diff changeset
32 size_t left;
857
3d437b1e5257 Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents: 839
diff changeset
33 size_t last_alloc_size;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34
72
c081870db35c Still memaligns
Timo Sirainen <tss@iki.fi>
parents: 67
diff changeset
35 /* unsigned char data[]; */
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 };
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
37 #define SIZEOF_POOLBLOCK (MEM_ALIGN(sizeof(struct pool_block)))
72
c081870db35c Still memaligns
Timo Sirainen <tss@iki.fi>
parents: 67
diff changeset
38
c081870db35c Still memaligns
Timo Sirainen <tss@iki.fi>
parents: 67
diff changeset
39 #define POOL_BLOCK_DATA(block) \
c081870db35c Still memaligns
Timo Sirainen <tss@iki.fi>
parents: 67
diff changeset
40 ((char *) (block) + SIZEOF_POOLBLOCK)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41
1489
826bed85c807 Added pool_get_name(), for debugging mostly.
Timo Sirainen <tss@iki.fi>
parents: 1350
diff changeset
42 static const char *pool_alloconly_get_name(pool_t pool);
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
43 static void pool_alloconly_ref(pool_t pool);
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
44 static void pool_alloconly_unref(pool_t pool);
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
45 static void *pool_alloconly_malloc(pool_t pool, size_t size);
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
46 static void pool_alloconly_free(pool_t pool, void *mem);
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
47 static void *pool_alloconly_realloc(pool_t pool, void *mem,
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
48 size_t old_size, size_t new_size);
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
49 static void pool_alloconly_clear(pool_t pool);
3233
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 3198
diff changeset
50 static size_t pool_alloconly_get_max_easy_alloc_size(pool_t pool);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
52 static void block_alloc(struct alloconly_pool *pool, size_t size);
330
1b503c732877 more ANSI-C fixes.
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
53
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
54 static struct pool static_alloconly_pool = {
1489
826bed85c807 Added pool_get_name(), for debugging mostly.
Timo Sirainen <tss@iki.fi>
parents: 1350
diff changeset
55 pool_alloconly_get_name,
826bed85c807 Added pool_get_name(), for debugging mostly.
Timo Sirainen <tss@iki.fi>
parents: 1350
diff changeset
56
330
1b503c732877 more ANSI-C fixes.
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
57 pool_alloconly_ref,
1b503c732877 more ANSI-C fixes.
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
58 pool_alloconly_unref,
1b503c732877 more ANSI-C fixes.
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
59
1b503c732877 more ANSI-C fixes.
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
60 pool_alloconly_malloc,
1b503c732877 more ANSI-C fixes.
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
61 pool_alloconly_free,
1b503c732877 more ANSI-C fixes.
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
62
1b503c732877 more ANSI-C fixes.
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
63 pool_alloconly_realloc,
1b503c732877 more ANSI-C fixes.
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
64
944
4f38538aa4a1 Added alloconly_pool field for checking if pool supports free()
Timo Sirainen <tss@iki.fi>
parents: 941
diff changeset
65 pool_alloconly_clear,
3233
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 3198
diff changeset
66 pool_alloconly_get_max_easy_alloc_size,
944
4f38538aa4a1 Added alloconly_pool field for checking if pool supports free()
Timo Sirainen <tss@iki.fi>
parents: 941
diff changeset
67
1782
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1741
diff changeset
68 TRUE,
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1741
diff changeset
69 FALSE
330
1b503c732877 more ANSI-C fixes.
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
70 };
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
72 pool_t pool_alloconly_create(const char *name, size_t size)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 {
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
74 struct alloconly_pool apool, *new_apool;
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
75 size_t min_alloc = sizeof(struct alloconly_pool) + SIZEOF_POOLBLOCK;
1786
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
76
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
77 #ifdef DEBUG
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
78 min_alloc += strlen(name) + 1;
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
79 #endif
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
80
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
81 /* create a fake alloconly_pool so we can call block_alloc() */
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
82 memset(&apool, 0, sizeof(apool));
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
83 apool.pool = static_alloconly_pool;
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
84 apool.refcount = 1;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
86 if (size < min_alloc)
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
87 size = nearest_power(size + min_alloc);
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
88 block_alloc(&apool, size);
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
89
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
90 /* now allocate the actual alloconly_pool from the created block */
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
91 new_apool = p_new(&apool.pool, struct alloconly_pool, 1);
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
92 *new_apool = apool;
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
93 #ifdef DEBUG
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
94 new_apool->name = p_strdup(&new_apool->pool, name);
1786
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
95 #endif
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
97 /* set base_size so p_clear() doesn't trash alloconly_pool structure. */
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
98 new_apool->base_size = new_apool->block->size - new_apool->block->left;
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
99 new_apool->block->last_alloc_size = 0;
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
100
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
101 return &new_apool->pool;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
104 static void pool_alloconly_destroy(struct alloconly_pool *apool)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 {
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
106 void *block;
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
107
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 /* destroy all but the last block */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 pool_alloconly_clear(&apool->pool);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 /* destroy the last block */
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
112 block = apool->block;
1111
1ae6cf799802 DEBUG: fill memory with 0xde before freeing it
Timo Sirainen <tss@iki.fi>
parents: 944
diff changeset
113 #ifdef DEBUG
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
114 memset(block, 0xde, SIZEOF_POOLBLOCK + apool->block->size);
1111
1ae6cf799802 DEBUG: fill memory with 0xde before freeing it
Timo Sirainen <tss@iki.fi>
parents: 944
diff changeset
115 #endif
1786
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
116
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
117 #ifndef USE_GC
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
118 free(block);
1786
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
119 #endif
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121
1489
826bed85c807 Added pool_get_name(), for debugging mostly.
Timo Sirainen <tss@iki.fi>
parents: 1350
diff changeset
122 static const char *pool_alloconly_get_name(pool_t pool)
826bed85c807 Added pool_get_name(), for debugging mostly.
Timo Sirainen <tss@iki.fi>
parents: 1350
diff changeset
123 {
826bed85c807 Added pool_get_name(), for debugging mostly.
Timo Sirainen <tss@iki.fi>
parents: 1350
diff changeset
124 struct alloconly_pool *apool = (struct alloconly_pool *) pool;
826bed85c807 Added pool_get_name(), for debugging mostly.
Timo Sirainen <tss@iki.fi>
parents: 1350
diff changeset
125
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
126 #ifdef DEBUG
1489
826bed85c807 Added pool_get_name(), for debugging mostly.
Timo Sirainen <tss@iki.fi>
parents: 1350
diff changeset
127 return apool->name;
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
128 #else
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
129 return "alloconly";
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
130 #endif
1489
826bed85c807 Added pool_get_name(), for debugging mostly.
Timo Sirainen <tss@iki.fi>
parents: 1350
diff changeset
131 }
826bed85c807 Added pool_get_name(), for debugging mostly.
Timo Sirainen <tss@iki.fi>
parents: 1350
diff changeset
132
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
133 static void pool_alloconly_ref(pool_t pool)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
135 struct alloconly_pool *apool = (struct alloconly_pool *) pool;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 apool->refcount++;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
140 static void pool_alloconly_unref(pool_t pool)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
142 struct alloconly_pool *apool = (struct alloconly_pool *) pool;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 if (--apool->refcount == 0)
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 pool_alloconly_destroy(apool);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
148 static void block_alloc(struct alloconly_pool *apool, size_t size)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
150 struct pool_block *block;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
152 i_assert(size > SIZEOF_POOLBLOCK);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
154 if (apool->block != NULL) {
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
155 /* each block is at least twice the size of the previous one */
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
156 if (size <= apool->block->size)
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
157 size += apool->block->size;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
159 size = nearest_power(size);
826
ca927eb6202f DEBUG: warn when growing pool
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
160 #ifdef DEBUG
ca927eb6202f DEBUG: warn when growing pool
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
161 i_warning("Growing pool '%s' with: %"PRIuSIZE_T,
ca927eb6202f DEBUG: warn when growing pool
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
162 apool->name, size);
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
163 #endif
826
ca927eb6202f DEBUG: warn when growing pool
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
164 }
ca927eb6202f DEBUG: warn when growing pool
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
165
1786
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
166 #ifndef USE_GC
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167 block = calloc(size, 1);
1786
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
168 #else
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
169 block = GC_malloc(size);
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
170 memset(block, 0, size);
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
171 #endif
409
849f3846212a Check return values for malloc()s and calloc()s.
Timo Sirainen <tss@iki.fi>
parents: 330
diff changeset
172 if (block == NULL)
3198
cb285bd5d8c9 If we run out of memory, exit with FATAL_OUTOFMEM status instead of dumping
Timo Sirainen <tss@iki.fi>
parents: 2297
diff changeset
173 i_fatal_status(FATAL_OUTOFMEM, "block_alloc(): Out of memory");
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 block->prev = apool->block;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175 apool->block = block;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 block->size = size - SIZEOF_POOLBLOCK;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 block->left = block->size;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
181 static void *pool_alloconly_malloc(pool_t pool, size_t size)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
183 struct alloconly_pool *apool = (struct alloconly_pool *) pool;
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
184 void *mem;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185
839
34cb1d196d2b String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents: 826
diff changeset
186 if (size == 0 || size > SSIZE_T_MAX)
34cb1d196d2b String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents: 826
diff changeset
187 i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);
34cb1d196d2b String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents: 826
diff changeset
188
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 size = MEM_ALIGN(size);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
190
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
191 if (apool->block->left < size) {
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
192 /* we need a new block */
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
193 block_alloc(apool, size + SIZEOF_POOLBLOCK);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
196 mem = POOL_BLOCK_DATA(apool->block) +
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
197 (apool->block->size - apool->block->left);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
198
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
199 apool->block->left -= size;
857
3d437b1e5257 Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents: 839
diff changeset
200 apool->block->last_alloc_size = size;
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
201 return mem;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
202 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203
2286
ee918986f94e pool_alloconly_free() can free the last allocation.
Timo Sirainen <tss@iki.fi>
parents: 1786
diff changeset
204 static void pool_alloconly_free(pool_t pool, void *mem)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205 {
2286
ee918986f94e pool_alloconly_free() can free the last allocation.
Timo Sirainen <tss@iki.fi>
parents: 1786
diff changeset
206 struct alloconly_pool *apool = (struct alloconly_pool *) pool;
ee918986f94e pool_alloconly_free() can free the last allocation.
Timo Sirainen <tss@iki.fi>
parents: 1786
diff changeset
207
ee918986f94e pool_alloconly_free() can free the last allocation.
Timo Sirainen <tss@iki.fi>
parents: 1786
diff changeset
208 /* we can free only the last allocation */
ee918986f94e pool_alloconly_free() can free the last allocation.
Timo Sirainen <tss@iki.fi>
parents: 1786
diff changeset
209 if (POOL_BLOCK_DATA(apool->block) +
ee918986f94e pool_alloconly_free() can free the last allocation.
Timo Sirainen <tss@iki.fi>
parents: 1786
diff changeset
210 (apool->block->size - apool->block->left -
ee918986f94e pool_alloconly_free() can free the last allocation.
Timo Sirainen <tss@iki.fi>
parents: 1786
diff changeset
211 apool->block->last_alloc_size) == mem) {
2297
59062bb4eaac If p_free() frees memory, it must also zero it..
Timo Sirainen <tss@iki.fi>
parents: 2286
diff changeset
212 memset(mem, 0, apool->block->last_alloc_size);
2286
ee918986f94e pool_alloconly_free() can free the last allocation.
Timo Sirainen <tss@iki.fi>
parents: 1786
diff changeset
213 apool->block->left += apool->block->last_alloc_size;
ee918986f94e pool_alloconly_free() can free the last allocation.
Timo Sirainen <tss@iki.fi>
parents: 1786
diff changeset
214 apool->block->last_alloc_size = 0;
ee918986f94e pool_alloconly_free() can free the last allocation.
Timo Sirainen <tss@iki.fi>
parents: 1786
diff changeset
215 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
218 static int pool_try_grow(struct alloconly_pool *apool, void *mem, size_t size)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219 {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
220 /* see if we want to grow the memory we allocated last */
857
3d437b1e5257 Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents: 839
diff changeset
221 if (POOL_BLOCK_DATA(apool->block) +
3d437b1e5257 Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents: 839
diff changeset
222 (apool->block->size - apool->block->left -
3d437b1e5257 Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents: 839
diff changeset
223 apool->block->last_alloc_size) == mem) {
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
224 /* yeah, see if we can grow */
857
3d437b1e5257 Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents: 839
diff changeset
225 if (apool->block->left >= size-apool->block->last_alloc_size) {
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
226 /* just shrink the available size */
857
3d437b1e5257 Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents: 839
diff changeset
227 apool->block->left -=
3d437b1e5257 Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents: 839
diff changeset
228 size - apool->block->last_alloc_size;
3d437b1e5257 Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents: 839
diff changeset
229 apool->block->last_alloc_size = size;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230 return TRUE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
234 return FALSE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
235 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
237 static void *pool_alloconly_realloc(pool_t pool, void *mem,
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
238 size_t old_size, size_t new_size)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
240 struct alloconly_pool *apool = (struct alloconly_pool *) pool;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
241 unsigned char *new_mem;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
242
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
243 if (new_size == 0 || new_size > SSIZE_T_MAX)
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
244 i_panic("Trying to allocate %"PRIuSIZE_T" bytes", new_size);
839
34cb1d196d2b String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents: 826
diff changeset
245
857
3d437b1e5257 Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents: 839
diff changeset
246 if (mem == NULL)
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
247 return pool_alloconly_malloc(pool, new_size);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
248
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
249 if (new_size <= old_size)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250 return mem;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
251
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
252 new_size = MEM_ALIGN(new_size);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
254 /* see if we can directly grow it */
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
255 if (!pool_try_grow(apool, mem, new_size)) {
422
5138499f90ad p_realloc() was buggy
Timo Sirainen <tss@iki.fi>
parents: 409
diff changeset
256 /* slow way - allocate + copy */
941
4d6b69558add Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
257 new_mem = pool_alloconly_malloc(pool, new_size);
422
5138499f90ad p_realloc() was buggy
Timo Sirainen <tss@iki.fi>
parents: 409
diff changeset
258 memcpy(new_mem, mem, old_size);
5138499f90ad p_realloc() was buggy
Timo Sirainen <tss@iki.fi>
parents: 409
diff changeset
259 mem = new_mem;
5138499f90ad p_realloc() was buggy
Timo Sirainen <tss@iki.fi>
parents: 409
diff changeset
260 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
261
422
5138499f90ad p_realloc() was buggy
Timo Sirainen <tss@iki.fi>
parents: 409
diff changeset
262 return mem;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
263 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
264
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
265 static void pool_alloconly_clear(pool_t pool)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
266 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
267 struct alloconly_pool *apool = (struct alloconly_pool *) pool;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 857
diff changeset
268 struct pool_block *block;
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
269 size_t avail_size;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
270
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
271 /* destroy all blocks but the oldest, which contains the
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
272 struct alloconly_pool allocation. */
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
273 while (apool->block->prev != NULL) {
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
274 block = apool->block;
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
275 apool->block = block->prev;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276
1111
1ae6cf799802 DEBUG: fill memory with 0xde before freeing it
Timo Sirainen <tss@iki.fi>
parents: 944
diff changeset
277 #ifdef DEBUG
1126
e106cde5255c DEBUG: we cleared wrong memory block..
Timo Sirainen <tss@iki.fi>
parents: 1111
diff changeset
278 memset(block, 0xde, SIZEOF_POOLBLOCK + block->size);
1111
1ae6cf799802 DEBUG: fill memory with 0xde before freeing it
Timo Sirainen <tss@iki.fi>
parents: 944
diff changeset
279 #endif
1786
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
280 #ifndef USE_GC
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281 free(block);
1786
49b6103dd2e0 Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
282 #endif
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
283 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
284
3238
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
285 /* clear the first block */
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
286 avail_size = apool->block->size - apool->base_size;
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
287 memset(PTR_OFFSET(POOL_BLOCK_DATA(apool->block), apool->base_size), 0,
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
288 avail_size - apool->block->left);
889a584bd953 Changed alloconly pools to call malloc() only once when creating the pool.
Timo Sirainen <tss@iki.fi>
parents: 3233
diff changeset
289 apool->block->left = avail_size;
857
3d437b1e5257 Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents: 839
diff changeset
290 apool->block->last_alloc_size = 0;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291 }
3233
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 3198
diff changeset
292
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 3198
diff changeset
293 static size_t pool_alloconly_get_max_easy_alloc_size(pool_t pool)
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 3198
diff changeset
294 {
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 3198
diff changeset
295 struct alloconly_pool *apool = (struct alloconly_pool *) pool;
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 3198
diff changeset
296
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 3198
diff changeset
297 return apool->block->left;
6396b4c0a721 Added p_get_max_easy_alloc_size().
Timo Sirainen <tss@iki.fi>
parents: 3198
diff changeset
298 }