Folks interested in this should absolutely look at the open source Cling project, which uses Clang/LLVM to JIT compile C++ in-process. https://github.com/root-project/cling I'm using Cling, as part of jank, a native Clojure dialect on LLVM, with C++ interop. This allows me to have truly interactive, dynamic programming, while still reaching into native code. jank source compiles to C++, which is then JIT compiled by…
My personal experience with ROOT REPL is that it's quite stateful, some error may make you want to restart the session I avoid it for anything longer than a few minutes of use
C and C++ Hot-Reload/Live Coding
51–60 of 102 posts
Re: C and C++ Hot-Reload/Live Coding
#52In one of the earlier episodes of the Handmade Hero series, Casey Muratori writes a hot-reloading functionality for C from scratch in about an hour (while giving detailed explanations of what he's doing). The following two episodes then improve upon the initial results. https://www.youtube.com/watch?v=WMSBRk5WG58
On one hand, I appreciate Muratori showing that loading code into your program dynamically isn’t actually difficult. On the other, the hard part of general hot reloading on systems that have tried it (from Smalltalk to VC++ Edit-and-Continue) is migrating obsolete state—or at least reliably telling the user when you can’t, so as to avoid leaving them to debug a mad world that could never be encountered in a fresh run…
Do you mean like in Lisp with update-instance-with-different-class for example?
https://www.lispworks.com/documentation/HyperSpec/Body/f_upd...
Re: C and C++ Hot-Reload/Live Coding
#53Earlier quoted context omitted.
My personal experience with ROOT REPL is that it's quite stateful, some error may make you want to restart the session I avoid it for anything longer than a few minutes of use
This. I haven't used it for a while, but my experience is that this whole idea is not worth the trouble. If you want to rapidly design and test algorithms in a JIT environment, just use Python. It's designed for that. You can always port it to c++ in the end if performance is an issue.
Ultimately, this isn't something Cling needs to worry about. You can have your cake and eat it, too. If that sounds too good to be true, know that it's how Clojure devs write all programs. We spin up the process and then send code to it from our editors, without needing to tear it down.
jank gives you this, in C++ land, including support for inline C++ within your Clojure code. I'll have a lot more demos coming out this year, but you can also check out the jank blog or my talks at ROOT's compiler research group and Clojure Conj 2023.
Re: C and C++ Hot-Reload/Live Coding
#54Maybe I'm just old and grumpy, but the subscription business model just puts me off. Nowadays when I read about some development tool (or just any product), I start with the price page. If there are only subscriptions available I stop reading and go on with my life.
Re: C and C++ Hot-Reload/Live Coding
#55You don't need anything complicated for this. All you need is to compile your code to a shared library that exports an 'update' method. See https://github.com/TomSmeets/quest-for-nothing/blob/master/a... You have to be careful with global variables however, they will get cleared to zero when the code is reloaded. To solve this either don't use globals or just restore them on reload.
Re: C and C++ Hot-Reload/Live Coding
#56I'm a fan of the opposite approach - serializing the program's state and launching a new instance which reads it. For one particular application I just had it keep all of it's useful state in /dev/shm (mmapped as a struct), double buffering it on every iteration of the main event loop. Of course that doesn't scale too well if you have dynamic allocations. This also has the advantage of not requiring platform specific…
Re: C and C++ Hot-Reload/Live Coding
#57Maybe I'm just old and grumpy, but the subscription business model just puts me off. Nowadays when I read about some development tool (or just any product), I start with the price page. If there are only subscriptions available I stop reading and go on with my life.
Devil's advocate: You aren't their target customer then?
Maybe a few larger companies as well, because those subscriptions tend to come with support, and larger companies love to throw maintenance to non-employees. But if they cared enough about not having a subscription, they'd make it themselves.
Re: C and C++ Hot-Reload/Live Coding
#58Earlier quoted context omitted.
On one hand, I appreciate Muratori showing that loading code into your program dynamically isn’t actually difficult. On the other, the hard part of general hot reloading on systems that have tried it (from Smalltalk to VC++ Edit-and-Continue) is migrating obsolete state—or at least reliably telling the user when you can’t, so as to avoid leaving them to debug a mad world that could never be encountered in a fresh run…
There is a tsoding daily video with hot code reloading in C [0]. He dicusses techniques for this. one of which is a "migration" approach, similar to database migrations. Where, for example, you have a version number in your struct. and a function for migrating from an old version to a new version. I don't think he implements it in that video though. [0] https://www.youtube.com/watch?v=Y57ruDOwH1g&t=15s
Video for how it works: https://www.youtube.com/watch?v=pjGngeKgni8
To migrate from one class version to another, I found the easiest way was to provide a callback method in the constructor where one could save the state from the old class, and read it into the new class. For example: https://github.com/jheruty/hscpp/blob/master/examples/simple...
Ultimately though the limitations of hot-swapping this way limits its usefulness. My understanding is that liveplusplus is much more full-featured.
Re: C and C++ Hot-Reload/Live Coding
#59fyi, "hot reload" is a native part of every operating system (consider, even trivially, forking or https://en.wikipedia.org/wiki/Dynamic_loading ). It's a sign of how bad developer tooling has been that live reload is sold as an add-on feature. DX seems always to see-saw between bill gate's c. 1990 demo of VB, and the compile-time speeds of a N' Wirth. At a guess, when the internet happened, all DX had to be thrown a…
fork() doesn't hot reload much of anything. exec() doesn't hot reload either. Dynamic loading doesn't hot reload either, more like hot load. Debuggers might hot-patch code to insert breakpoints, but that's not the same thing as replacing running code. Sure, the debugger might execute scripts you associate with breakpoints, but that's also not exactly the same thing as replacing the running code. Mind you, debuggers d…
Well, one counter-example: Erlang.
But Erlang is typically the exception to any rule.
Re: C and C++ Hot-Reload/Live Coding
#60Earlier quoted context omitted.
fork() doesn't hot reload much of anything. exec() doesn't hot reload either. Dynamic loading doesn't hot reload either, more like hot load. Debuggers might hot-patch code to insert breakpoints, but that's not the same thing as replacing running code. Sure, the debugger might execute scripts you associate with breakpoints, but that's also not exactly the same thing as replacing the running code. Mind you, debuggers d…
> ... a) single-threaded Well, one counter-example: Erlang. But Erlang is typically the exception to any rule.