Memory Mapped Files

What happened to ObjectFiler?

For those of you used to traditional Smalltalk there is a mechanism for dumping an Object model to a file for use at a later date. At first glance you may show dismay that STMT doesn't appear to have such a mechanism.

Well I am here to tell you that not only does it have a mechanism to do this, but the approach is the fastest possible approach on a Windows platform.

Recall that STMT objects use their address as their hash value. This means that if it were possible to dump a block of memory containing objects to disk and later reload it, STMT would not know the difference. Luckily Windows provides a way to create a file in memory, save that file to disk and subsequently load the file back into memory.

STMT internally uses memory mapped files to manage method source code. The SOURCES.BIN file is in fact a memory mapped file that is loaded when the image starts up. The nice thing about memory mapped files is that the whole object model does not have to be loaded at once. Windows will load portions of the file on demand in exactly the same way as it loads (and unloads) virtual memory to (and from) the Windows swap file.

The end result is speed on both the save (a simple dump memory to file) and load (on demand loading).

Load And Save Object models

To save an object model use:

MappedObjectStream saveObject: myObject fileName: 'C:\\Temp\\MyObjects.bin' size: 50*1024*1024

This will serialize myObject and all its decendants into the file MyObjects.bin the size is required and must be big enough to store the object model (in this case 50 Mb).

To inspect an object filer file, use the Transcript Tools Menu->Inspectors->Object file inspector

To load an object model, use:

stream := MappedObjectStream new.

stream openFile: 'C:\\Temp\\MyObjects.bin'.

myObject := stream getRootObject