views:

147

answers:

6

What is a Smalltalk "image"? Is it like serializing a Smalltalk run-time?

+6  A: 

Most popular programming systems separate program code (in the form of class definitions, functions or procedures) from program state (such as objects or other forms of application data). They load the program code when an application is started, and any previous application state has to be recreated explicitly from configuration files or other data sources. Any settings the application programmer doesn't explicitly save, you have to set back up whenever you restart.

Many Smalltalk systems, however, do not differentiate between application data (objects) and code (classes). In fact, classes are objects themselves. Therefore most Smalltalk systems store the entire application state (including both Class and non-Class objects) in an image file. The image can then be loaded by the Smalltalk virtual machine to restore a Smalltalk-like system to a previous state.

http://en.wikipedia.org/wiki/Smalltalk#Image-based_persistence

Robert Harvey
Another way to see it is that this is really like the system images you get with OS virtualization software like VirtualBox or VMWare. Except the OS in the image is the Smalltalk system, and it's not organized like a filesystem, but as objects.
Damien Pollet
+3  A: 

http://book.seaside.st/book/getting-started/pharo-squeak/what-is-image

All Smalltalk objects live in something called an image. An image is a snapshot of memory containing all the objects at a given point in time.

Second hit on google.

skaffman
+3  A: 

When the smalltalk VM starts, it loads a saved state of objects (yes: including open file streams, windows, threads and more) from the "image" into its memory and resumes execution where it left when the image was saved. At any time during your work, you can "save an image" (aka: a snapshot of the current overall state) into an image file. You can keep multiple images on your disk. Useful if you work on different projects. Images are often (but not in all smalltalk systems) portable across architectures; for example, a squeak image can be loaded into bot a windows and a mac (and even an android) squeak VM. Images are not portable across dialects, and sometimes not across versions within a dialect.

Images usually contain everything - even the debugger, compiler, editors, browsers etc. However, for deployment, it is sometimes useful to "strip" (i.e. remove unused stuff) from an image - either to hide secrets (;-) or to make it smaller (for embedded or mobile devices). Most Smalltalks cannot live without an image, with the exception of Smalltalk/X and (I think) S#-Smalltalk (but I am on thin ice here...)

To save and transport source code, images are not useful - use either fileout in standard format or in xml or in any other transport format (there are many). Images are also not useful for marshalling/unmarshalling; use xml, binarystorage, databases, glorb or any other serialization method for that.

blabla999
A small precision: file streams are not kept open in the saved image. Some classes can register to do cleanup/reinitialization when the image is saved or reloaded. File descriptors, sockets, the screen bitmap... all point to state that is outside the image, so they would be invalid if the file is removed while the image is stopped, or if the image is moved to a different host.Threads are implemented completely inside the image (like Java's green threads), so they do not map to a system thread, and they can be saved as is, with a debugger etc
Damien Pollet
You are right, but actually: Smalltalk/X even tries to reopen a file and reposition it, iff it is a regular file. It is - of course - not done by the VM, but by the classes' optional reinitialize methods (actually: returnFromSnapshot). Also, in st/x, there is no screen bitmap, but instead a number of win32 or x topWindows to recreate. Fair enough, it is actually up to the programmer to add such a returnFromSnapshot method and to decide, what can and how it is to be reconstructed after a so called snapin.
blabla999
(you are of course also right, that the state is external to the image; however, if you keep a copy of (some of) the state, you can recreate a window, replace the old window-handle, remap and redraw the new window, for example. And that is what is done in the returnFromSnapshot methods).
blabla999
+1  A: 

I recommend you to read http://pharobyexample.org/ First chapter it says:

"The current system image is a snapshot of a running Pharo system, frozen in time. It consists of two files: an .image file, which contains the state of all of the objects in the system (including classes and methods, since they are objects too), and a .changes file, which contains a log of all of the changes to the source code of the system. In Figure 1.1, these files are called pharo.image and pharo.changes."

HTH

Mariano Peck
+2  A: 

The Smalltalk image is a very interesting beast. Look at it as a kind of immortality. Many current Smalltalk systems, Pharo, Squeak, VisualWorks among them, share a common ancestor, that is, a Smalltalk image from Xerox PARC. This common ancestor however is not some remote thing, but actually still alive in those modern systems. The modern variants were produced by sending messages to the objects in that image. Some of those messages actually morphed the current objects. Classes are full-blown objects, and creating new classes is done by sending messages to class objects. Some of the objects in a Smalltalk image may date back to 1972, when the first Smalltalk image bootstrapped! Smalltalk images never die, they just fade into something potentially fundamentally different. You should view your application building as not fundamentally different from creating a new Smalltalk version.

robject
A: 

Put simply, a Smalltalk image is an image of the Smalltalk environment which has been saved at a given point in time. When this image is reloaded into the Smalltalk runtime system, everything is as it was at the time the image was saved.

Images saved by one Smalltalk system cannot, in general, be loaded by a different Smalltalk system.

I find image-based development incredibly empowering. If I get interrupted I can save the image, and when I get back to it I'm right back where I was. Debuggers that were open are still open, waiting to continue. There's very little "got to figure out how to get back where I was" - it's more "OK, let's continue...".

Share and enjoy.

Bob Jarvis