什么是 Smalltalk“图像”?
什么是 Smalltalk“图像”?这就像序列化 Smalltalk 运行时吗?
What is a Smalltalk "image"? Is it like serializing a Smalltalk run-time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
什么是 Smalltalk“图像”?这就像序列化 Smalltalk 运行时吗?
What is a Smalltalk "image"? Is it like serializing a Smalltalk run-time?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
大多数流行的编程系统将程序代码(以类定义、函数或过程的形式)与程序状态(例如对象或其他形式的应用程序数据)分开。它们在应用程序启动时加载程序代码,并且必须从配置文件或其他数据源显式重新创建任何先前的应用程序状态。应用程序程序员没有明确保存的任何设置,您都必须在重新启动时进行备份。
然而,许多 Smalltalk 系统并不区分应用程序数据(对象)和代码(类)。事实上,类本身就是对象。因此,大多数 Smalltalk 系统将整个应用程序状态(包括类和非类对象)存储在图像文件中。然后,Smalltalk 虚拟机可以加载该映像,以将类 Smalltalk 系统恢复到之前的状态。
http://en.wikipedia.org/wiki/Smalltalk#Image-based_persistence
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
Smalltalk 图像是一个非常有趣的野兽。将其视为一种不朽。当前的许多 Smalltalk 系统(其中包括 Pharo、Squeak、VisualWorks)都有一个共同的祖先,即来自 Xerox PARC 的 Smalltalk 映像。然而,这个共同的祖先并不是什么遥远的东西,而是实际上仍然存在于那些现代系统中。现代变体是通过向该图像中的对象发送消息而产生的。其中一些消息实际上改变了当前对象。类是成熟的对象,创建新类是通过向类对象发送消息来完成的。 Smalltalk 镜像中的一些对象可以追溯到 1972 年,当时第一个 Smalltalk 镜像启动了! Smalltalk 图像永远不会消亡,它们只是逐渐消失,变成可能根本不同的东西。您应该将您的应用程序构建视为与创建新的 Smalltalk 版本没有根本区别。
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.
当smalltalk VM启动时,它会将保存的对象状态(是的:包括打开的文件流、窗口、线程等)从“映像”加载到内存中,并从保存映像时离开的地方恢复执行。
在工作过程中的任何时候,您都可以将图像(又名:当前整体状态的快照)“保存”到图像文件中。您可以在磁盘上保存多个图像。如果您从事不同的项目,这很有用。
图像通常(但并非在所有 Smalltalk 系统中)可以跨架构移植;例如,squeak 图像可以加载到 Windows 和 Mac(甚至 Android)squeak 虚拟机中。图像不能跨方言移植,有时也不能跨方言内的版本移植。
映像通常包含所有内容 - 甚至调试器、编译器、编辑器、浏览器等。但是,对于部署,有时从映像中“剥离”(即删除未使用的内容)很有用 - 要么隐藏秘密 (;-) 要么制作它更小(对于嵌入式或移动设备)。
大多数 Smalltalks 没有图像就无法生存,除了 Smalltalk/X 和(我认为)S#-Smalltalk(但我在这里如履薄冰......)
为了保存和传输源代码,图像没有用 - 使用其中之一文件输出采用标准格式、xml 或任何其他传输格式(有很多)。
图像对于编组/解编组也没有什么用处;为此使用 xml、binarystorage、数据库、glorb 或任何其他序列化方法。
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.
它对整个系统中的所有内容进行序列化,包括所有开发工作和所有用户数据。除了运行时环境的内核之外的所有内容。
Smalltalk 与 Java 一样,运行在运行符号字节码的虚拟机上,并且它包含诸如垃圾收集器之类的低级内容。这使得 Smalltalk 非常便携,而且非常“一次编写,随处运行”。
不出所料,这就是 Java 的灵感来源。因此,Smalltalk VM (StVM) 相当于 Java 运行时环境。
在 Smalltalk 中,其他所有内容都存储在 RAM 中。代码库是为 StVM 即时动态编译的。您通过运行垂直和水平最终用户应用程序构建的所有对象数据。您对窗口环境及其外观所做的所有自定义。您编写的所有新代码。您已加载到虚拟机上以在音乐播放器中播放的歌曲。您正在使用或已加载的任何其他数据、代码或对象。
它们都存在于 PC 的内存中。
您可能需要定期将当前播放状态保存到磁盘。当您这样做时,您会暂时冻结 Smalltalk VM,并将所有内容复制到单个磁盘文件中。该磁盘文件称为映像文件,默认情况下,在 PC 上的大多数发行版中(无论它们运行的是 Linux、MacOS、Windows 还是 RiscOS),它都会具有 .image 后缀。
这类似于您在典型 PC 上的文字处理程序或电子表格中保存正在进行的工作的方式。只不过此保存包含电子表格应用程序本身所用的电子表格代码的最新版本。
Smalltalk 系统确实有其他方法来保护您的数据。如果您开发任何软件,或更改 Smalltalk 系统编写的任何代码库,它会将每个更改实时记录到磁盘。
您可以选择编写代码或加载应用程序,该应用程序可以将源代码及其关联的数据结构保存到分布式源代码存储库或本地磁盘上的存储库。或者关系数据库。或者对象数据库或新流行的 NoSQL 数据库。
大多数预先编写的应用程序都会将数据即时备份到磁盘或数据库。
镜像是整个Smalltalk系统的保存,(除了虚拟机。虚拟机相当于Java运行时环境。其他的东西都存储在镜像中。
写一个新的文件系统来访问底层操作系统的光盘?那就是(并且所有更改也已由 Smalltalk 系统自动记录到磁盘)。
将大量数据输入到基于 Smalltalk 图像的对象数据库中吗
?您的 Smalltalk 系统吗?只需返回到使用首次安装 Smalltalk 时收到的映像文件即可。想要每小时保存一次映像,然后恢复到 4 小时前吗?只需加载 4 小时前的映像文件即可。
该映像是 Smalltalk 系统内存中所有内容的副本,除了系统中较小的、不变的、至关重要的部分,即虚拟机。
It's serialising everything in the whole system, including all development work and all user data. Everything apart from the kernel of the runtime environment.
Smalltalk, like Java, runs on a Virtual Machine running symbolic bytecode, and it contains low-level things like the garbage collector. This makes Smalltalk very portable, and also very write-once-run-anywhere.
Unsurprisingly, this was the inspiration for Java. So the Smalltalk VM (StVM) is the equivalent of the Java Runtime Environment.
In Smalltalk, everything else is stored in RAM. The codebase, which is dynamically compiled on-the-fly for the StVM. All the object data that you've built up by running your vertical and horizontal end-user apps. All the customisation you've done to the windowing environment and its appearance. All the new code you've written. A song you have loaded onto the VM to play in a music player. Any other data, code or objects you're using or have loaded in.
It's all live in the PC's memory.
Periodically, you may want to save the current-state-play to disk. When you do that, you freeze the Smalltalk VM momentarily, and it copies everything into a single disk-file. That disk-file is called the image file, and by default it will have a .image suffix in most distributions on PCs (whether they are running Linux, MacOS, Windows or RiscOS).
It's a like the way you save your work-in-progress when you are in a word-processor or a spreadsheet on a typical PC. Except that this save includes the latest version of the spreadsheet code that the spreadsheet app itself is made out of.
The Smalltalk system does have other ways of securing your data. If you develop any software, or alter any of the codebase that the Smalltalk system is written in, it logs every change to disk in real-time.
You have the option of writing code, or loading an app, that will can save your source-code and it's associated data structures, to distributed source code repositories, or to repositories on your local disc. Or to relational databases. Or to object databases or the newly-fashionable NoSQL databases.
Most pre-written apps backup the data to disk(s) or database(s) on-the-fly.
The image is a save of the entire Smalltalk system, (apart from the Virtual Machine. The Virtual Machine is equivalent to the Java Runtime Environment. Everything else is stored in the image.
Write a new File System to access the underlying OS's discs? That's in the image. (and all the changes have also been logged to disk automatically by the Smalltalk system).
Enter a whole bunch of data into your Smalltalk image-based object database? That's in the image.
Want to do a factory-reset to your Smalltalk system? Simply go back to using the image file you received when you first installed Smalltalk. Want to save the image every hour on the hour, and then restore back to 4 hours ago? Just load the image file from four hours ago.
The image is a copy of everything that the Smalltalk system has in memory. Except for the small, unchanging, vital proportion of the system which is the Virtual Machine.
我建议您阅读Pharo 示例。引用第一章的内容:
“当前系统映像是正在运行的 Pharo 系统的快照,
时间被冻结。它由两个文件组成:一个 .image 文件,其中包含
系统中所有对象的状态(包括类和方法,
因为它们也是对象),以及一个 .changes 文件,其中包含所有的日志
系统源代码的更改。在图1.1中,这些文件
称为 pharo.image 和 pharo.changes。”
HTH
I recommend you read Pharo By Example. To quote from its first chapter,
"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
http://book.seaside.st/book/入门/pharo-squeak/what-is-image
在谷歌上第二次点击。
http://book.seaside.st/book/getting-started/pharo-squeak/what-is-image
Second hit on google.
简而言之,Smalltalk 镜像是在给定时间点保存的 Smalltalk 环境的镜像。当该映像重新加载到 Smalltalk 运行时系统中时,一切都与保存映像时一样。
一般来说,一个 Smalltalk 系统保存的图像不能由另一个 Smalltalk 系统加载。
我发现基于图像的开发具有令人难以置信的力量。如果我被打扰,我可以保存图像,当我回到图像时,我就回到了原来的位置。打开的调试器仍然打开,等待继续。很少有“必须弄清楚如何回到原来的位置”——更多的是“好吧,让我们继续……”。
分享并享受。
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.
在几乎所有其他语言中(据一些高级 SAP 开发人员告诉我,除了 ABAP),您有一个明确的分离:
在 Smalltalk 中,所有这些都可以 - 注意可以 - 在图像中。
理论上,您可以在加载的映像中部署 Smalltalk 应用程序,该映像会带来所有数据和逻辑并在启动时运行该应用程序。
在实践中,根据我的经验,你往往不会因为某些原因而这样做。
如果你留在图像中,你就可以使用一切,无论好坏。
类是对象,方法是对象,因此您实际上可以执行一些操作,例如
在方法中添加 a,运行一些调用该方法的代码,在执行时更改方法,重新编译它并使代码继续。
您还可以做一些很棒的事情,例如将方法名称作为字符串传递给方法,然后执行参数,而无需在任何地方的代码中可见。
这两件事都非常适合学习和尝试。对于生产代码或维护生产代码不太好。
我一开始遇到的困难是,例如,对于 UI 创建,您在 Smalltalk 图像中创建一个窗口,然后由操作系统“第二次”创建该窗口,其中包含窗口句柄和所有内容。
当然,您可以使用 Smalltalk 图像保存窗口,它也会再次打开(通常),但内部发生的情况是,有一个窗口列表(即所有 UI 组件)已与图像一起保存在他们的 Smalltalk 状态。
在映像启动期间,有一个进程会迭代此列表并要求操作系统重新创建所有这些列表。
理论上,您可以对操作系统提供的所有内容执行此操作:
文件句柄、资源句柄、端口等
实际上,您可能不想这样做。
我工作过的公司有很好的初学者代码教程,可以在保存图像之前运行,以免第二天重新启动时遇到麻烦。
理想情况下,您可以将 Smalltalk 图像概念与持久性结合起来,并将所有对象存储在真实的数据库中。
然而,我不知道是否有任何 Smalltalk 方言做到了这一点。
In almost every other language (apart from ABAP as far as I have been told by some senior SAP developers), you have a clear separation:
In Smalltalk, all of this can be - note can - in the image.
In theory, you can deploy a Smalltalk application in a loaded image which brings all the data and logic and runs the application at startup.
In practice, as far as my experience goes, you tend not to do that for reasons.
If you stay inside the image, you have everything available at your disposal, for good or ill.
Classes are objects, methods are objects, so you can actually do things like add a
in a method, run some code which calls this method, change the method while it is being executed, recompile it and have the code continue.
You can also do wonderful things like passing method names as string to a method and then performing the argument without having this visible in code anywhere.
Both things are very good for learning and trying out. Not so good for production code or maintaining producion code.
The thing I was struggling with in the beginning was that for instance for UI creation, you create a window in the Smalltalk image which is then created "a second time" by the OS, with window handle and everything.
Of course, you can save the window with the Smalltalk image, it will also open up again (normally), but what happens internally is that there is a list of windows (i.e. all the UI components) which have been saved with the image in their Smalltalk state.
During Image Startup, there is a process that iterates over this list and asks the OS to recreate all of them.
In theory, you can do this for everything the OS offers:
file handles, resource handles, ports and so on
In practice, you probably dont want to do that.
The companies I worked at had nice beginner tutorials of code to run before saving your image in order not to get into trouble when restarting the next day.
Ideally, you could combine a Smalltalk image concept with peristence and just store all your objects in a real database.
I do not have the overview whether any Smalltalk dialect has done this, however.