Lines Matching +full:block +full:- +full:size

29 ** ('osize' is the old size, 'nsize' is the new size)
31 ** - frealloc(ud, p, x, 0) frees the block 'p' and returns NULL.
35 ** - frealloc(ud, NULL, x, s) creates a new block of size 's'
36 ** (no matter 'x'). Returns NULL if it cannot create the new block.
38 ** - otherwise, frealloc(ud, b, x, y) reallocates the block 'b' from
39 ** size 'x' to size 'y'. Returns NULL if it cannot reallocate the
40 ** block to the new size.
47 #define callfrealloc(g,block,os,ns) ((*g->frealloc)(g->ud, block, os, ns)) argument
58 #define cantryagain(g) (completestate(g) && !g->gcstopem)
65 ** First allocation will fail except when freeing a block (frees never
69 static void *firsttry (global_State *g, void *block, size_t os, size_t ns) { in firsttry() argument
73 return callfrealloc(g, block, os, ns); in firsttry()
76 #define firsttry(g,block,os,ns) callfrealloc(g, block, os, ns) argument
90 ** Minimum size for arrays during parsing, to avoid overhead of
91 ** reallocating to size 1, then 2, and then 4. All these arrays
97 void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize, in luaM_growaux_() argument
100 int size = *psize; in luaM_growaux_() local
101 if (nelems + 1 <= size) /* does one extra element still fit? */ in luaM_growaux_()
102 return block; /* nothing to be done */ in luaM_growaux_()
103 if (size >= limit / 2) { /* cannot double it? */ in luaM_growaux_()
104 if (l_unlikely(size >= limit)) /* cannot grow even a little? */ in luaM_growaux_()
106 size = limit; /* still have at least one free place */ in luaM_growaux_()
109 size *= 2; in luaM_growaux_()
110 if (size < MINSIZEARRAY) in luaM_growaux_()
111 size = MINSIZEARRAY; /* minimum size */ in luaM_growaux_()
113 lua_assert(nelems + 1 <= size && size <= limit); in luaM_growaux_()
115 newblock = luaM_saferealloc_(L, block, cast_sizet(*psize) * size_elems, in luaM_growaux_()
116 cast_sizet(size) * size_elems); in luaM_growaux_()
117 *psize = size; /* update only when everything else is OK */ in luaM_growaux_()
123 ** In prototypes, the size of the array is also its number of
128 void *luaM_shrinkvector_ (lua_State *L, void *block, int *size, in luaM_shrinkvector_() argument
131 size_t oldsize = cast_sizet((*size) * size_elem); in luaM_shrinkvector_()
134 newblock = luaM_saferealloc_(L, block, oldsize, newsize); in luaM_shrinkvector_()
135 *size = final_n; in luaM_shrinkvector_()
143 luaG_runerror(L, "memory allocation error: block too big"); in luaM_toobig()
150 void luaM_free_ (lua_State *L, void *block, size_t osize) { in luaM_free_() argument
152 lua_assert((osize == 0) == (block == NULL)); in luaM_free_()
153 callfrealloc(g, block, osize, 0); in luaM_free_()
154 g->GCdebt -= osize; in luaM_free_()
162 static void *tryagain (lua_State *L, void *block, in tryagain() argument
167 return callfrealloc(g, block, osize, nsize); /* try again */ in tryagain()
176 void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { in luaM_realloc_() argument
179 lua_assert((osize == 0) == (block == NULL)); in luaM_realloc_()
180 newblock = firsttry(g, block, osize, nsize); in luaM_realloc_()
182 newblock = tryagain(L, block, osize, nsize); in luaM_realloc_()
187 g->GCdebt = (g->GCdebt + nsize) - osize; in luaM_realloc_()
192 void *luaM_saferealloc_ (lua_State *L, void *block, size_t osize, in luaM_saferealloc_() argument
194 void *newblock = luaM_realloc_(L, block, osize, nsize); in luaM_saferealloc_()
201 void *luaM_malloc_ (lua_State *L, size_t size, int tag) { in luaM_malloc_() argument
202 if (size == 0) in luaM_malloc_()
206 void *newblock = firsttry(g, NULL, tag, size); in luaM_malloc_()
208 newblock = tryagain(L, NULL, tag, size); in luaM_malloc_()
212 g->GCdebt += size; in luaM_malloc_()