Imported from ../lua-5.0.3.tar.gz.
[lua.git] / src / lmem.h
blob1bb4fde0b2aa40f1e551a503244bc972e4ef1adb
1 /*
2 ** $Id: lmem.h,v 1.26 2002/05/01 20:40:42 roberto Exp $
3 ** Interface to Memory Manager
4 ** See Copyright Notice in lua.h
5 */
7 #ifndef lmem_h
8 #define lmem_h
11 #include <stddef.h>
13 #include "llimits.h"
14 #include "lua.h"
16 #define MEMERRMSG "not enough memory"
19 void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size);
21 void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem,
22 int limit, const char *errormsg);
24 #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0)
25 #define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0)
26 #define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \
27 cast(lu_mem, n)*cast(lu_mem, sizeof(t)), 0)
29 #define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t))
30 #define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t)))
31 #define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \
32 cast(lu_mem, n)*cast(lu_mem, sizeof(t))))
34 #define luaM_growvector(L,v,nelems,size,t,limit,e) \
35 if (((nelems)+1) > (size)) \
36 ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e)))
38 #define luaM_reallocvector(L, v,oldn,n,t) \
39 ((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \
40 cast(lu_mem, n)*cast(lu_mem, sizeof(t)))))
43 #endif