What gives Smalltalk the ability to do image persistence, and why can't languages like Ruby/Python serialize themselves?

后端 未结 4 745
情深已故
情深已故 2021-02-07 04:55

In smalltalk, you\'re able to save the state of the world into an image file. I assume this has to do with Smalltalk\'s ability to \"serialize\" itself -- that is, objects can p

4条回答
  •  难免孤独
    2021-02-07 05:36

    Extending upon Bert Freudenberg’s excellent answer.

    1) Is this (ie object's ability to serialize their own source code) an accurate understanding?

    Nope. As Bert pointed out a Smalltalk image is simply a memory snapshot. The single-source-of-truth of both Smalltalk objects and Smalltalk programs is their memory representation. This is a huge difference to other languages, where programs are represented as text files.

    2) What is the challenge in adding this ability to modern languages (non-lisp, obviously)?

    Technically, bootstrapping an application from a memory snapshot should be possible for most languages. If I am not mistaken there are solutions that use this approach to speedup startup times for Java applications. You'd have to agree on a canonical memory representation though and you'd need to make care to reinitialize native resources upon restarting the program. For example, in Smalltalk, open files and network connecting are reopened. And also, there's a startup hook to fix the endianness of numbers.

    3) Is "serialization" the right word? What's the correct jargon?

    Hibernation is the term.

提交回复
热议问题