lmem.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. ** $Id: lmem.h,v 1.21 2001/02/20 18:15:33 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. void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size);
  12. void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem,
  13. int limit, const l_char *errormsg);
  14. #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0)
  15. #define luaM_freelem(L, b, t) luaM_realloc(L, (b), sizeof(t), 0)
  16. #define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \
  17. ((lu_mem)(n)*(lu_mem)sizeof(t)), 0)
  18. #define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t))
  19. #define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t)))
  20. #define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, \
  21. (lu_mem)(n)*(lu_mem)sizeof(t)))
  22. #define luaM_growvector(L,v,nelems,size,t,limit,e) \
  23. if (((nelems)+1) > (size)) \
  24. ((v)=(t *)luaM_growaux(L,v,&(size),sizeof(t),limit,e))
  25. #define luaM_reallocvector(L, v,oldn,n,t) \
  26. ((v)=(t *)luaM_realloc(L, v,(lu_mem)(oldn)*(lu_mem)sizeof(t), \
  27. (lu_mem)(n)*(lu_mem)sizeof(t)))
  28. #endif