lua-users home
lua-l archive

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


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


-- 
+------------------------------------------+
| Tom Pike thwpike@p3international.org     |
| P3 International www.p3international.org |
+------------------------------------------+