lua-users home
lua-l archive

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


bil til <biltil52@gmail.com> 于2023年7月26日周三 18:54写道:
>
> Am Mi., 26. Juli 2023 um 12:37 Uhr schrieb 云风 Cloud Wu <cloudwu@gmail.com>:
> > Using a pointer in the struct TString to refer the string memory, so
> > that the constant strings in the precompiled binary code can be put into ROM.
>
> Thank you for fast answer... .
>
> Just I would hope to come around doing such quite basic things to Lua code... .
>
> So you think, that after loading a Lua code file, the complete
> pre-compiled code is saved to some string object / or several string
> objects?

I maintain a fork of lua (https://github.com/ejoy/lua/tree/skynet54)
for our project skynet (https://github.com/cloudwu/skynet).
It allows multiple lua VMs to share constant lua objects including
strings, function prototypes (code chunk), and even the read-only
tables.

The motivation of the fork is saving the memory when we have thousands
lua VMs in one process (multiple threads), because most of these VMs
would load the same lua code.
I load the lua code in one VM, and share it with other VMs. The first
VM loading code never run after loading code, and everything in it is
constant.

I think you can also use it to make a VM (with code and some read-only
table) persistent into ROM, and run a VM in RAM with some sharing data
(strings, code chunks, tables, etc).

-- 
http://blog.codingnow.com