|
|
3.1 Memory accessing methods
GNU Smalltalk provides methods for directly accessing real memory.
You may access memory either as individual bytes, or as 32 bit words.
You may read the contents of memory, or write to it. You may also
find out the size and alignment of scalar C types, and determine the
real memory address of an object or the real memory address of the
OOP table that points to a given object, by using messages to the
Memory class, described below.
- Method: Memory bigEndian
- Answers
true on machine architectures where the most significant
byte of a 32 bit integer has the lowest address (e.g. 68000 and Sparc),
and false on architectures where the least significant byte occurs at
the lowest address (e.g. Intel and VAX).
- Variable: C*Size
-
- Variable: C*Alignment
- The
CIntSize , CLongSize , CShortSize , CFloatSize ,
CDoubleSize , CPtrSize , CDoubleAlignment globals
are provided by the VM as part of the Smalltalk dictionary, and are there for
compatibility with old versions of GNU Smalltalk. However you should not use
them and, instead, send messages like CInt sizeof or
CDouble alignof .
- Method: Object asOop
- Returns the index of the OOP for anObject. This index is immume
from garbage collection and is the same value used by default as
an hash value for anObject (it is returned by Object's implementation
of
hash and identityHash ).
- Method: Integer asObject
- Converts the given OOP index (not address) back to an object.
Fails if no object is associated to the given index.
- Method: Integer asObjectNoFail
- Converts the given OOP index (not address) back to an object.
Returns nil if no object is associated to the given index.
Other methods in ByteArray and Memory allow to read various C types
(doubleAt: , ucharAt: , etc.). For examples of using
asOop and asObject , look at the Blox source code in
`blox/tk/BloxBasic.st'.
Another interesting class is ObjectMemory. This provides a few
methods that enable one to tune the virtual machine"s usage of
memory; many methods that in the past were instance methods of
Smalltalk or class methods of Memory are now class methods of
ObjectMemory. In addition, and that's what the rest of this
section is about, the virtual machines signals events to its
dependants exactly through this class.
The events that can be received are
- returnFromSnapshot
- This is sent every time an image is restarted, and substitutes
the concept of an init block that was present in previous
versions.
- aboutToQuit
- This is sent just before the interpreter is exiting, either
because
ObjectMemory quit was sent or because the specified
files were all filed in. Exiting from within this event might
cause an infinite loop, so be careful.
- aboutToSnapshot
- This is sent just before an image file is created. Exiting from
within this event will leave any preexisting image untouched.
- finishedSnapshot
- This is sent just after an image file is created. Exiting from
within this event will not make the image unusable.
|