lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Apologies, I realise that this is a bit vague, I have missed out a bit
of the email.  The reason that I want to check for the size of the table
is to be able to check if adding an element to the table was possible
with the amount of free memory, ie check that it would not use all, or
worse more than the availiable memory.


				Tom

On Mon, 2005-02-28 at 15:53 +1100, Tom Pike wrote:
> I have been reading the "Programming in Lua" book, and I congratulate
> Roberto on a fine book.  A question did arise whilst reading the book,
> is it possible to find the memory usage of a table?
> 
> eg in C you could always check for the return value of malloc:
> 
> if( ()malloc() == NULL ) {
> 	throw_graceful_error();
> }
> 
> is there a way of doing this in Lua:
> 
> if ( table_size(table) + sizeof(new_table_member) ) >= \
> avaliable_memory() then
> 	table[i]=new_table_member;
> else
> 	throw_graceful_error();
> end
> 
> the above is in no way meant to be reasonable code, more of an idea of
> what I would like to do.  I assume in low memory situations, the Lua
> interpreter would throw an error when it ran out of memory? (sure other
> things would grind to a halt as well!) I would much rather have the
> script throw the error and have some chance of exiting gracefully.
> 
> 
> 			Many Thanks,
> 
> 
> 			    Tom
> 
>