lua-users home
lua-l archive

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

2009/6/10 Duncan Cross <>:
> On Wed, Jun 10, 2009 at 2:55 PM, Niklas Frykholm<> wrote:
>> 2009/6/10 Olivier Hamel <>:
>> Currently, if you want to create Complex or Vector3 type you have to
>> do it as a table or a userdata. And if you do a serious ammount of
>> processing on them, the ammount of garbage generated by simple
>> arithmetic operations will soon put a significant strain on the
>> system. (You could use a pool of such objects, but that would mean
>> resorting to manual memory management with all its pains - especially
>> when you are using it for something as simple as numbers.)
> Perhaps I am misunderstanding, but if the pool is a table that has
> been set to have weak values (i.e. its metatable's __mode field is set
> to 'v'), you should not have to do any manual memory management -
> values that only exist in the pool will be eligible for garbage
> collection.

My description was a bit short, but the whole point of having a pool
was to avoid generating garbage. (By using a free object from the
pool, rather than creating a new one, whenever a new object is
needed.) But this requires us to manually track which objects in the
pool are free or not (i.e., manual memory management).

If the objects in the pool are eligible for garbage collection, then
the pool doesn't really buy us anything. We will generate the same
ammount of garbage with the pool as without it.

// Niklas