lua-users home
lua-l archive

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

On 23.05.2018 17:05, 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?

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.

Jeremy J.
Instead of trying to figure it out based on assumtion and theory I recommend you to test your code in patched Lua built. You can easily set the allocator of Lua and in that you can activate a trace once you call your function.

bool trace_active = false;
void *l_my_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
    if(trace_active) {
        printf("Lua allocation!");
    lua_Alloc(ud, ptr, osize, nsize);

All you have to do is to set trace_active to true just before you call your function and to false right after it. Otherwise you will have many wrong traces.