Search code examples
c++luashared-memory

Can I store a lua_State in shared memory?


I'm guessing not (or, if possible will almost certainly not be worth my time).

The way I'm thinking is to construct a mirror object that contain's offset_ptr's that also sits in the class owns the lua_State that the child processes can use to obtain the locations of the relevant pointers to the state, whether or not that's feasible... there's also other objects that lua_ methods would probably access that I'm not sure how I would pass them the correct addresses...

Guessing I would need a special allocator too, not sure if this is supported?


Solution

  • Since Lua is implemented purely in standard C, allocating a lua_State in shared memory is clearly not supported out-of-the-box. You could look at modifying the source to implement that functionality manually, but it probably wouldn't be worth the trouble. Instead you should keep lua_States out of shared memory, and just copy any important data into shared memory if necessary.