void PtrArray::shrink() { unsigned int new_size=l_near_pow_2(len+1); pdata=(use_l_alloc ? (void **)l_realloc(pdata,new_size*sizeof(void *),size*sizeof(void *)) : (void **)realloc(pdata,new_size*sizeof(void *)) ); //pdata=(void **)realloc(pdata,new_size*sizeof(void *)); //pdata=(void **)l_realloc(pdata,new_size*sizeof(void *),size*sizeof(void *)); size=new_size; }
/* ** generic allocation routine. */ void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) { lua_assert((oldsize == 0) == (block == NULL)); if (size == 0) { if (block != NULL) { l_free(block, oldsize); block = NULL; } else return NULL; /* avoid `nblocks' computations when oldsize==size==0 */ } else if (size >= MAX_SIZET) luaG_runerror(L, "memory allocation error: block too big"); else { block = l_realloc(block, oldsize, size); if (block == NULL) { if (L) luaD_throw(L, LUA_ERRMEM); else return NULL; /* error before creating state! */ } } if (L) { lua_assert(G(L) != NULL && G(L)->nblocks > 0); G(L)->nblocks -= oldsize; G(L)->nblocks += size; } return block; }
void PtrSizeArray::shrink() { unsigned int new_size=l_near_pow_2(len+1); //pdata=(PtrSize_t *)realloc(pdata,new_size*sizeof(PtrSize_t)); pdata=(PtrSize_t *)l_realloc(pdata,new_size*sizeof(PtrSize_t),size*sizeof(PtrSize_t)); size=new_size; }