7.5 The Store structure

7.5.1 Machine pointers and stores

Much foreign data can consist of pointers, represented by explicit machine addresses. Clearly such data may be literally represented within an ML store. However, as noted above, stores can expand in size. To ensure the uniformity of addressing, this expansion is implemented by copying the data in them. Unfortunately this copying invalidates any explicit pointers to other data elements contained in the same store. Other explicit pointers referring to non-local (or remote) data naturally remain valid.

Explicit machine pointers must therefore be treated with care. For example, there is a facility for providing 'local' pointers, which are represented as a local offset from the base address of the store. The use of small indices here means that conventional array indexing can be used directly from ML. Of course, this facility also requires the ability to convert between local indices and actual machine addresses.

The advantage of using 'local' pointers is that they remain invariant under expansion of the store. However, their disadvantage is that they are meaningless if used out of context. Hence, local pointers must not be passed into foreign code -- they must first be converted into machine addresses. The FI provides tools for performing these conversions.

One way of avoiding these difficulties is to work with stores that cannot be expanded, but which have sufficient static space allocated to start with. In this case, machine addresses cannot be invalidated due to store expansion and so can be passed to foreign code with impunity.


MLWorks Reference Manual (version 1.0) - 3 DEC 1996

Generated with Harlequin WebMaker