I love these little "factoid" comments that you hand out from time to time. What would be even better is a book with all the nitty-gritty details of the software you've written, along with all the misadventures in doing so.
You can name it: 'Bright Moments'
I'd be happy to place an advanced order if it leans you in that direction!
If we're bikeshedding the book title, surely "Bright Ideas" warrants a mention.
Something using Bright Lines would be my first thought.
See also: Emacs's old unexec() function. How do you speed up a bunch standard library lisp loading and initialization? Just do it once then write a new exe out with all your state pre-computed. Genius.
Yup, and early TeX did it too. You could run a memory dump of a previously initialized version to improve start-up times.
For a modern take on similar idea see also this discussion from a while ago:
"Improving startup time in Atom with V8 snapshots"
Re:You can't copy code with memcpy
by WalterBright on Thursday December 30, 2021 @03:06AM
(#29734726)
I stole that idea from the 1970's FORTRAN program ADVENT, the precursor to Zork.
I was amazed that I never ran across another DOS program that used the technique.
there's also unfork(2)!
Do you unfork then unexec or unexec then unfork?
Re:You can't copy code with memcpy
by withinrafael on Thursday December 30, 2021 @12:51PM
(#29739111)
How did it break? COMDAT usage is optional today. (Perhaps it wasn't when first created?)
Re:You can't copy code with memcpy
by WalterBright on Thursday December 30, 2021 @01:29PM
(#29739659)
COMDATs aren't placed sequentially by the linker. Also, zero initialized data got placed in a separate section.
I've pre-packed game asset data to the end of EXE files using this trick and it seems that newer neural network virus scanners seem to the the only type of scanner to pick it up. So we may even lose the ability to do that soon once these type of scanner become more popular/prevalent.
Very fast & easy.
Of course, it broke when COMDATs were introduced.
I did a similar thing with my text editor. The colors were configurable. The usual way was to have a configuration file, which the editor would read upon startup. But floppy disk systems were unbearably slow. So what I did was take the address of the configuration data in the data segment. I'd work backwards to where those bytes were in the EXE file, and patch the EXE file. This worked great!
Until the advent of virus scanners, which broke that. Virus scanners hated self-modifying EXE files.