[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua reference re-use
- From: Coda Highland <chighland@...>
- Date: Thu, 30 Jul 2015 13:57:14 -0700
On Thu, Jul 30, 2015 at 1:55 PM, Nagaev Boris <bnagaev@gmail.com> wrote:
> On Thu, Jul 30, 2015 at 5:19 PM, Tim Perkins <tprk77@gmail.com> wrote:
>> I've also struggled with luaL_ref and luaL_unref in the past. So I will try
>> to help.
>>
>> These functions create a sort of linked list of free indexes, always
>> starting at the zeroth element of the table.
>>
>> I would recommend writing your own functions, to meet your specific needs.
>> The original functions are not too complicated, and you can find the source
>> in "lauxlib.c". In your case it should be pretty easy because you can just
>> use a monotonically increasing integer.
>
> Good idea! This simple solution allows not only to detect
> use-after-free bugs but also memory leaks (ref without unref).
>
> Why the standard implementation reuses old references? To keep the
> table in array form (rather than hash)?
Pretty much, yeah. It's an efficiency thing.
/s/ Adam