#include "wsint.h"Include dependency graph for wsfalloc.c:

Go to the source code of this file.
Functions | |
| WsFastMalloc * | ws_f_create (size_t block_size) |
| void | ws_f_destroy (WsFastMalloc *pool) |
| void * | ws_f_malloc (WsFastMalloc *pool, size_t size) |
| void * | ws_f_calloc (WsFastMalloc *pool, size_t num, size_t size) |
| void * | ws_f_memdup (WsFastMalloc *pool, const void *ptr, size_t size) |
| void * | ws_f_strdup (WsFastMalloc *pool, const char *str) |
|
||||||||||||||||
|
Definition at line 150 of file wsfalloc.c. References size, ws_f_malloc(), and WsFastMalloc. Referenced by expr_alloc(), stmt_alloc(), ws_list_append(), ws_list_new(), and ws_stmt_linearize(). 00151 {
00152 void *p = ws_f_malloc(pool, num * size);
00153
00154 if (p == NULL)
00155 return p;
00156
00157 memset(p, 0, num * size);
00158
00159 return p;
00160 }
|
Here is the call graph for this function:

|
|
Definition at line 74 of file wsfalloc.c. References WsFastMallocRec::block_size, ws_calloc(), and WsFastMalloc. Referenced by compile_stream(). 00075 {
00076 WsFastMalloc *pool = ws_calloc(1, sizeof(WsFastMalloc));
00077
00078 if (pool == NULL)
00079 return NULL;
00080
00081 pool->block_size = block_size;
00082
00083 return pool;
00084 }
|
Here is the call graph for this function:

|
|
Definition at line 87 of file wsfalloc.c. References WsFastMallocRec::blocks, WsFastMallocBlockRec::next, ws_free(), WsFastMalloc, and WsFastMallocBlock. Referenced by compile_stream(). 00088 {
00089 WsFastMallocBlock *b, *bnext;
00090
00091 if (pool == NULL)
00092 return;
00093
00094 for (b = pool->blocks; b; b = bnext) {
00095 bnext = b->next;
00096 ws_free(b);
00097 }
00098 ws_free(pool);
00099 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 102 of file wsfalloc.c. References WsFastMallocRec::block_size, WsFastMallocRec::blocks, WsFastMallocBlockRec::next, WsFastMallocRec::ptr, result, size, WsFastMallocRec::size, WsFastMallocRec::user_bytes_allocated, ws_malloc(), WsFastMalloc, and WsFastMallocBlock. Referenced by ws_f_calloc(), ws_f_memdup(), ws_f_strdup(), ws_formal_parameter(), and ws_variable_declaration(). 00103 {
00104 unsigned char *result;
00105
00106 /* Keep the blocks aligned, because this function is used to allocate
00107 * space for structures containing longs and such. */
00108
00109 if (size % sizeof(long) != 0) {
00110 size += sizeof(long) - (size % sizeof(long));
00111 }
00112
00113 if (pool->size < size) {
00114 size_t alloc_size;
00115 WsFastMallocBlock *b;
00116
00117 /* Must allocate a fresh block. */
00118 alloc_size = pool->block_size;
00119 if (alloc_size < size)
00120 alloc_size = size;
00121
00122 /* Allocate the block and remember to add the header size. */
00123 b = ws_malloc(alloc_size + sizeof(WsFastMallocBlock));
00124
00125 if (b == NULL)
00126 /* No memory available. */
00127 return NULL;
00128
00129 /* Add this block to the memory pool. */
00130 b->next = pool->blocks;
00131 pool->blocks = b;
00132
00133 pool->ptr = ((unsigned char *) b) + sizeof(WsFastMallocBlock);
00134 pool->size = alloc_size;
00135 }
00136
00137 /* Now we can allocate `size' bytes of data from this pool. */
00138
00139 result = pool->ptr;
00140
00141 pool->ptr += size;
00142 pool->size -= size;
00143
00144 pool->user_bytes_allocated += size;
00145
00146 return result;
00147 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 163 of file wsfalloc.c. References d, size, ws_f_malloc(), and WsFastMalloc. Referenced by ws_expr_const_string(). 00164 {
00165 unsigned char *d = ws_f_malloc(pool, size + 1);
00166
00167 if (d == NULL)
00168 return NULL;
00169
00170 memcpy(d, ptr, size);
00171 d[size] = '\0';
00172
00173 return d;
00174 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 177 of file wsfalloc.c. References ws_f_malloc(), and WsFastMalloc. Referenced by ws_expr_assign(), ws_expr_call(), ws_expr_postfix_var(), ws_expr_symbol(), ws_expr_unary_var(), and yyparse(). 00178 {
00179 size_t len;
00180 char *s;
00181
00182 if (str == NULL)
00183 return NULL;
00184
00185 len = strlen(str) + 1;
00186 s = ws_f_malloc(pool, len);
00187
00188 if (s == NULL)
00189 return NULL;
00190
00191 memcpy(s, str, len);
00192
00193 return s;
00194 }
|
Here is the call graph for this function:
