next up previous contents index
Next: 6.13.2.1 Non-backtrackable Storage Up: 6.13 Asserting, Retracting, and Previous: 6.13.1 Reading Dynamic Code   Contents   Index


6.13.2 The storage Module: Associative Arrays and Backtrackable Updates

XSB provides a high-level interface that allows the creation of ``objects'' that efficiently manage the storage of facts or of associations between keys and values. Of course, facts and associative arrays can be easily managed in Prolog itself, but the storage module is highly efficient and supports the semantics of backtrackable updates as defined by Transaction logic [6] in addition to immediate updates. The semantics of backtrackable updates means that an update made by the storage module may is provisional until the update is committed. Otherwise, if a subgoal calling the update fails, the change is undone. The commit itself may be made either by the predicate storage_commit/1, or less cleanly by cutting over the update itself.

A storage object $O$ is referred to by a name, which must be a Prolog atom. $O$ can be associated either with a set of facts or a set of key-value pairs. Within a given storage object each key is associated with a unique value: however since keys and values can be arbitrary Prolog terms, this constraint need not be a practical restriction. A storage object $O$ is created on demand, simply by calling (a backtrackable or non-backtrackable) update predicate that refers to $O$. However to reclaim $O$'s space within a running thread, the predicate storage_reclaim_space/1 must be called. Backtackable non-backtrackable updates can be made to the same storage object, although doing so may not always be a good programming practice.

If multiple threads are used, each storage object is private to a thread, and space for a storage object is reclaimed upon a thread's exit. Thread-shared storage objects may be supported in future versions.

All the predicates described in this section must be imported from module storage.



Subsections
next up previous contents index
Next: 6.13.2.1 Non-backtrackable Storage Up: 6.13 Asserting, Retracting, and Previous: 6.13.1 Reading Dynamic Code   Contents   Index
Terrance Swift 2007-10-05