top | item 30719630

(no title)

kubkon | 4 years ago

Nice! V does it the same way as Nim though, right? From quickly browsing over the sources, it looks like it is based on dynamic library hot swapping https://github.com/vlang/v/tree/master/vlib/v/live

discuss

order

mihaigalos|4 years ago

Not very familiar with the mechanism, sorry. The vlang community is very reactive, both in GH Issues and the Discord channel.

They can support you with good advice in the further developing of Zig, I'm sure! Good luck!

amedvednikov|4 years ago

V author here. Yes, dynamic library hot swapping, but we're also planning to implement a more sophisticated way to do this.

mihaigalos|4 years ago

What is the more sophisticated way? Do you have an Issue / Milestone in GitHub?

WithinReason|4 years ago

What are the pros/cons of one vs. the other?

kubkon|4 years ago

Great question. With the presented approach in Zig, since you work on the binary directly, after you finish your hot-code reloading session, you can still run the generated binary from disk (and debug it or whatnot) as all writes to memory were also committed to the underlying file on disk. There is therefore no need to recompile your program to an executable from a dynamic library as I guess would be the case for approach taken by Nim/V.

The presented approach might also be more resource efficient as it is writing directly to program's memory rather than unloading and reloading a dynamic library, but this is very much a guess and I would need to do some benchmarking to get a better feel for it.

In general though, this approach is possible in Zig since first of all, we have our own linker for each target file format (ELF, MachO, COFF-coming-soon-tm), secondly, the compiler generates the executable file directly, and thirdly, incremental updates are super granular in order to minimise writes to the file as much as possible.