next up previous contents
Next: 6.8 Compressing relations Up: 6 Creating New Relations Previous: 6.6 Generating code from

6.7 Avoiding copy overhead

When the relations have large formulas, copying and assigning relations can be costly. In some instances, such as when you return a relation from a function, or when you copy a locally-declared relation into a list or array, the relation being copied may be thrown away after the operation.

The library has a mechanism to make these copies more efficient. It does reference counting of relations in some limited cases, so that no copy is actually made; each relation shares the same ``body''. In order to get this behavior, call the function Relation::finalize() on your relation. This essentially marks the relation as ``read-only'' as far as the library is concerned. That means that there are no constraints being built, and no more formula nodes can be added anywhere in its formula tree. You'll still be able to perform high-level operations on it, and you'll still be able to query it and simplify it -- the library detects this and does an actual copy if any operation will change the relation.



omega@cs.umd.edu

Web Accessibility