GEOS SDK TechDocs
|
|
4 VM Chains
|
4.2 VM Chain Utilities
A VM chain is composed of two kinds of blocks: chain blocks (which are linked to at most one other block), and tree blocks (which may be linked to any number of other blocks). One block is the head of the chain; chain utility routines can be passed the handle of this block, and they will act on all the blocks in the chain. If a block is a "leaf" block, it should contain a null handle. An example of a VM chain with tree blocks is shown in the figure below.
Be warned that a VM chain must not contain any circuits. That is, by following links, you should not be able to go from any block back to itself; and there should not be two different routes from any one block to any other. If you create such a VM chain and pass it to a chain utility, the results are undefined. It is your responsibility to make sure no loops occur.
A VM chain block is the same as any other VM block, with one exception: The block must begin with a
VMChainLink
structure. This structure contains a single data field,
VMC_next
, which is the handle of the next block in the chain. If the block is in a chain but has no next link,
VMC_next
is a null handle. This means, for example, that LMem heaps cannot belong to a VM chain (since LMem heaps must begin with an
LMemHeader
structure).
In addition to chain blocks, a VM chain may contain a tree block. A tree block may have several links to blocks.
A tree block begins with a
VMChainTree
structure. This structure has three fields:
VMCT_meta
VMChainLink
structure. Every block in a VM chain, including a tree block, must begin with such a structure. However, to indicate that this is a tree block, the
VMC_next
field must be set to the special value VM_CHAIN_TREE.
VMCT_offset
VMChainTree
structure and the first link. If you do not put data in this block, set this field to
sizeof(VMChainTree)
.
VMCT_count
Any of the links may be a null handle. To delete the last link in the block, just decrement
VMCT_count
(and, if you wish, resize the block). To delete a link in the midst of a block, just change the link to a null handle without decrementing
VMCT_count
. To add a new link to a VM tree block, you can either add the handle after the last link and increment
VMCT_count
; or you can replace a null handle (if there are any) with the new handle, without changing
VMCT_count
.
GEOS SDK TechDocs
|
|
4 VM Chains
|
4.2 VM Chain Utilities