CW 329

Bart Demoen, Phuong-Lan Nguyen, Ruben Vandeginste
Copy_term/2 and garbage collection

Abstract

Copying terms has a central role in every Prolog system as some predicates must use it. Apart from copy_term/2 itself, there is at least findall/3 and throw/1 that (can) use it and in many implementations, also some form of globale variables uses an underlying copying routine. On the other hand, most Prolog systems use a garbage collector that moves terms on the heap, either by a copying or a sliding algorithm. Copy_term/2 and garbage collection are clearl y related: findall/3 is even advertised sometimes as a substitute for true garbage collection. Starting from a simple experiment that establishes the relative performance of copy_term/2 and garbage collection , it is described how the garbage collection algorithms can be used for (non-destructively) copying terms, and how the essentials of copy_term can be used to implement a series of garbage collectors. Experimental results show good speedups in the latter case. Information on the cache behaviour of all variants is provided and partly explains the observed performance.

report.pdf / mailto: B. Demoen