diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-12-28 10:55:41 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-12-28 10:55:41 -0200 |
commit | 0183b8030c80f57b87874ff7867ccdb172d9d3dc (patch) | |
tree | 1033b5a84489a2f1f1bd210b1b120155cd7aeed7 /ltable.c | |
parent | 8c49e198654567f770a7d5081b886a7c35201d81 (diff) | |
download | lua-0183b8030c80f57b87874ff7867ccdb172d9d3dc.tar.gz lua-0183b8030c80f57b87874ff7867ccdb172d9d3dc.tar.bz2 lua-0183b8030c80f57b87874ff7867ccdb172d9d3dc.zip |
`free' gets size of the block: complete control over memory use
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 15 |
1 files changed, 4 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.60 2000/12/04 18:33:40 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.61 2000/12/22 16:57:46 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -27,9 +27,6 @@ | |||
27 | #include "ltable.h" | 27 | #include "ltable.h" |
28 | 28 | ||
29 | 29 | ||
30 | #define gcsize(L, n) (sizeof(Hash)+(n)*sizeof(Node)) | ||
31 | |||
32 | |||
33 | 30 | ||
34 | #define TagDefault LUA_TTABLE | 31 | #define TagDefault LUA_TTABLE |
35 | 32 | ||
@@ -167,8 +164,6 @@ static void setnodevector (lua_State *L, Hash *t, luint32 size) { | |||
167 | ttype(&t->node[i].key) = ttype(&t->node[i].val) = LUA_TNIL; | 164 | ttype(&t->node[i].key) = ttype(&t->node[i].val) = LUA_TNIL; |
168 | t->node[i].next = NULL; | 165 | t->node[i].next = NULL; |
169 | } | 166 | } |
170 | L->nblocks -= gcsize(L, t->size); /* old size */ | ||
171 | L->nblocks += gcsize(L, size); /* new size */ | ||
172 | t->size = size; | 167 | t->size = size; |
173 | t->firstfree = &t->node[size-1]; /* first free position to be used */ | 168 | t->firstfree = &t->node[size-1]; /* first free position to be used */ |
174 | } | 169 | } |
@@ -181,7 +176,6 @@ Hash *luaH_new (lua_State *L, int size) { | |||
181 | L->roottable = t; | 176 | L->roottable = t; |
182 | t->mark = t; | 177 | t->mark = t; |
183 | t->size = 0; | 178 | t->size = 0; |
184 | L->nblocks += gcsize(L, 0); | ||
185 | t->node = NULL; | 179 | t->node = NULL; |
186 | setnodevector(L, t, luaO_power2(size)); | 180 | setnodevector(L, t, luaO_power2(size)); |
187 | return t; | 181 | return t; |
@@ -189,9 +183,8 @@ Hash *luaH_new (lua_State *L, int size) { | |||
189 | 183 | ||
190 | 184 | ||
191 | void luaH_free (lua_State *L, Hash *t) { | 185 | void luaH_free (lua_State *L, Hash *t) { |
192 | L->nblocks -= gcsize(L, t->size); | 186 | luaM_freearray(L, t->node, t->size, Node); |
193 | luaM_free(L, t->node); | 187 | luaM_freelem(L, t, Hash); |
194 | luaM_free(L, t); | ||
195 | } | 188 | } |
196 | 189 | ||
197 | 190 | ||
@@ -226,7 +219,7 @@ static void rehash (lua_State *L, Hash *t) { | |||
226 | if (ttype(&old->val) != LUA_TNIL) | 219 | if (ttype(&old->val) != LUA_TNIL) |
227 | *luaH_set(L, t, &old->key) = old->val; | 220 | *luaH_set(L, t, &old->key) = old->val; |
228 | } | 221 | } |
229 | luaM_free(L, nold); /* free old array */ | 222 | luaM_freearray(L, nold, oldsize, Node); /* free old array */ |
230 | } | 223 | } |
231 | 224 | ||
232 | 225 | ||