lua-users home
lua-l archive

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


Hi all,

We are using lua 4 as scripting language in an open source project on dreamcast. Since it is a realtime application which create several temporary objects every frame, we used the incremental garbage collector patch, which works very fine, thanks to Paul Liu !

In this project, in particular we have many temporary userdata that are created and forgot every frame. I found that one problem is that lua count the memory used by userdata as only the memory taken to manage it internally. So I added some function that let me declare how much additional memory does the userdata takes. This amount can be changed anytime, so that even complex object that make several reallocation can keep up to date memory usage information (of course, this may not be desirable to do so in every case). Also , most of the time, giving some empirical value may be enough (and more simple to implement).

An example of use is :

lua_pushusertag(L, data, tag);
lua_setsz(L, 1024); /* declare 1024 bytes of memory usage for this userdata */


Also a shortcut may exist to make both at the same time

lua_pushusertagsz(L, data, tag, 1024); /* create a new userdata and declare it's memory usage */



What do you think about adding this feature into lua ?


Vincent Penne.