lua-users home
lua-l archive

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


2009/12/9 steve donovan <steve.j.donovan@gmail.com>:
> On Wed, Dec 9, 2009 at 12:47 PM, Jerome Vuarand
> <jerome.vuarand@gmail.com> wrote:
>> program to have several independent heaps. A way to avoid that is to
>> avoid malloc in C modules, and only use lua_newuserdata (or the
>> lua_Alloc directly) for memory allocation.
>
> I see the point - if extensions are always using Lua for memory
> allocation, then they are only really going to be using the allocator
> in the Lua dll.  However, there is a lot of C Lua extensions out there
> that use malloc.  Then there is also the issue of external required
> dlls and their dependencies.

Maybe I shouldn't have mixed the two concepts (though I'm not sure how
you understood it). To be clear (for others, mostly), you can use
malloc even with mixed DLL runtimes, as long as free call uses the
same runtime as the malloc, and that condition is verifiable. Using
the Lua allocator is merely an optimization.

For external dependencies, the same applies. But libs that are
targeting Windows have probably been faced to the object (e.g. memory
block) ownership passing problem at some point, and are likely to
provide a solution to that (for example the ability to use a custom
allocator, like Lua does), so binding C modules should use these
facilities somehow. I've bound many C libraries to Lua on windows, and
so far I've not met such problems.