lua-users home
lua-l archive

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

On Wed, May 23, 2018 at 11:05:03AM -0400, Jeremy Jurksztowicz wrote:
> Hi, probably asked somewhere on the archive but my searches are turning up nil.
> Wondering if I can get any understanding of what kind of Lua code I can
> write that will not invoke the memory allocator. i.e. if I have a function
> that does not create any tables or strings, and I make sure that the
> lua_State has a lot of stack space, and pause the GC, and I only operate
> on numbers in a preallocated table, would it be reasonable to assume that
> the code would not block, and be suitable for signal processing?

AFAIU, in that scenario there shouldn't be any allocation. You might want to
carefully read the table code to see if certain access patterns could
trigger a realloc to a smaller hash or array index.

For a recent project I'm likewise expecting this behavior--that simple
scalar operations and read-only table accesses won't trigger allocation.
Though I don't really need a hard guarantee like you do so haven't invested
much time in verifying my assumptions.

Whether or not your code blocks depends on the runtime environment and what
you mean by blocking. Even without allocation or explicit file I/O (directly
or indirectly in the VM), you could still block on a page fault. You might
want to use the allocator hooks so you can pin pages in memory.

> I have been looking through the code and docs, but if anyone can point to
> some definitive material or share some caveats or encouragement, I’d
> really appreciate that.

I don't think there's such definitive material but would be pleasantly
surprised if there is. You may want to check for material or discussions
related to embedded forks like eLua.