new way to handle "growing" vectors

This commit is contained in:
Roberto Ierusalimschy
1999-02-25 12:16:26 -03:00
parent 24a2c08145
commit 26d1e21c89
5 changed files with 52 additions and 67 deletions

8
lmem.h
View File

@@ -1,5 +1,5 @@
/*
** $Id: lmem.h,v 1.5 1997/12/17 20:48:58 roberto Exp roberto $
** $Id: lmem.h,v 1.6 1998/12/15 14:59:43 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@@ -18,15 +18,15 @@
#define memEM "not enough memory"
void *luaM_realloc (void *oldblock, unsigned long size);
int luaM_growaux (void **block, unsigned long nelems, int size,
void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
char *errormsg, unsigned long limit);
#define luaM_free(b) luaM_realloc((b), 0)
#define luaM_malloc(t) luaM_realloc(NULL, (t))
#define luaM_new(t) ((t *)luaM_malloc(sizeof(t)))
#define luaM_newvector(n,t) ((t *)luaM_malloc((n)*sizeof(t)))
#define luaM_growvector(old,n,t,e,l) \
(luaM_growaux((void**)old,n,sizeof(t),e,l))
#define luaM_growvector(old,nelems,inc,t,e,l) \
((t *)luaM_growaux(old,nelems,inc,sizeof(t),e,l))
#define luaM_reallocvector(v,n,t) ((t *)luaM_realloc(v,(n)*sizeof(t)))