lua/lmem.h

Go to the documentation of this file.
00001 /*
00002 ** $Id: lmem.h,v 1.38 2011/12/02 13:26:54 roberto Exp $
00003 ** Interface to Memory Manager
00004 ** See Copyright Notice in lua.h
00005 */
00006 
00007 #ifndef lmem_h
00008 #define lmem_h
00009 
00010 
00011 #include <stddef.h>
00012 
00013 #include "llimits.h"
00014 #include "lua.h"
00015 
00016 
00017 #define luaM_reallocv(L,b,on,n,e) \
00018     ((cast(size_t, (n)+1) > MAX_SIZET/(e)) ?  /* +1 to avoid warnings */ \
00019         (luaM_toobig(L), (void *)0) : \
00020         luaM_realloc_(L, (b), (on)*(e), (n)*(e)))
00021 
00022 #define luaM_freemem(L, b, s)   luaM_realloc_(L, (b), (s), 0)
00023 #define luaM_free(L, b)     luaM_realloc_(L, (b), sizeof(*(b)), 0)
00024 #define luaM_freearray(L, b, n)   luaM_reallocv(L, (b), n, 0, sizeof((b)[0]))
00025 
00026 #define luaM_malloc(L,s)    luaM_realloc_(L, NULL, 0, (s))
00027 #define luaM_new(L,t)       cast(t *, luaM_malloc(L, sizeof(t)))
00028 #define luaM_newvector(L,n,t) \
00029         cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
00030 
00031 #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s))
00032 
00033 #define luaM_growvector(L,v,nelems,size,t,limit,e) \
00034           if ((nelems)+1 > (size)) \
00035             ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
00036 
00037 #define luaM_reallocvector(L, v,oldn,n,t) \
00038    ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
00039 
00040 LUAI_FUNC l_noret luaM_toobig (lua_State *L);
00041 
00042 /* not to be called directly */
00043 LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
00044                                                           size_t size);
00045 LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
00046                                size_t size_elem, int limit,
00047                                const char *what);
00048 
00049 #endif
00050 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:04 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs