lmem.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. ** $Id: lmem.h,v 1.25 2001/11/28 20:13:13 roberto Exp roberto $
  3. ** Interface to Memory Manager
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lmem_h
  7. #define lmem_h
  8. #include <stddef.h>
  9. #include "llimits.h"
  10. #include "lua.h"
  11. #define MEMERRMSG "not enough memory"
  12. void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size);
  13. void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem,
  14. int limit, const char *errormsg);
  15. #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0)
  16. #define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0)
  17. #define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \
  18. cast(lu_mem, n)*cast(lu_mem, sizeof(t)), 0)
  19. #define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t))
  20. #define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t)))
  21. #define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \
  22. cast(lu_mem, n)*cast(lu_mem, sizeof(t))))
  23. #define luaM_growvector(L,v,nelems,size,t,limit,e) \
  24. if (((nelems)+1) > (size)) \
  25. ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e)))
  26. #define luaM_reallocvector(L, v,oldn,n,t) \
  27. ((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \
  28. cast(lu_mem, n)*cast(lu_mem, sizeof(t)))))
  29. #endif