[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.1 (work1) now available
- From: Miles Bader <miles@...>
- Date: Sat, 07 Apr 2012 16:18:28 +0900
Rena <hyperhacker@gmail.com> writes:
>> BTW, I should note that the way SWIG allocates objects like this is to
>> use C++ "new" to create the actual object, and then allocate a Lua
>> userdata containing a pointer to the C++ object, some info about its
>> type, and a Lua metatable with a __gc entry that does the deallocation.
>>
>> I don't think it's particularly efficient for small objects like this,
>> but as far I can tell it does the right thing, and the userdata in
>> this case is about the same size as the referenced data, so Lua's GC
>> should have roughly the right idea of how much memory is being used.
>
> A boxed pointer, in other words. I don't know of any other method to
> deal with C++ objects that expect the use of new and delete.
Many C++ objects work perfectly fine allocated in other ways though.
Certainly if I was hand-rolling this code, I'd just use placement-new to
construct the object inside the userobject itself.
-Miles
--
Bigot, n. One who is obstinately and zealously attached to an opinion that
you do not entertain.
- References:
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Roberto Ierusalimschy
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Roberto Ierusalimschy
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Roberto Ierusalimschy
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Rena