lua-users home
lua-l archive

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

On Mon, Jul 21, 2014 at 10:10 AM, Javier Guerra Giraldez
<> wrote:
> On Mon, Jul 21, 2014 at 11:27 AM, Coda Highland <> wrote:
>> You could also allocate a tiny
>> pointer-sized userdata and then use its __gc metamethod to free the
>> original data block.
> while that works and is very common, keep in mind that Lua will only
> 'see' very tiny objects; if you allocate a lot of big objects you can
> consume a lot of memory and the Lua GC might not bother to collect
> those 'tiny' objects.

Sure. Every solution has its tradeoffs, but it's an option to keep in
mind if GC pressure doesn't prove to be an issue for your use case
compared to the trouble of doing a copy on construction. (Though a
question to be asked is if the structure in question is amenable to
memcpy, because that really rather simplifies matters if you can get
away with it.)

/s/ Adam