From jan@swi.psy.uva.nl  Tue Apr 18 16:11:16 2000
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id QAA25803;
	Tue, 18 Apr 2000 16:11:16 +0200 (MET DST)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id QAA18453;
	Tue, 18 Apr 2000 16:11:47 +0200
Date: Tue, 18 Apr 2000 16:11:47 +0200
Message-Id: <200004181411.QAA18453@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: term comparison in foreign code
To: "Jacoby Thwaites" <jthwaite@michaelhouse.co.uk>, <jan@swi.psy.uva.nl>
In-Reply-To: Jacoby Thwaites's message of Tue, 18 Apr 2000 14:57:37 +0100
Phone: +31 - 20 - 525 6121
Cc: prolog@gollem.swi.psy.uva.nl

> Jan,  I am using references to index grounded terms in both the
> recorded and compiled databases.
> 
> E.g.
> ...
> recordz( main_key, interesting(a,b,c), Reference),
> recordz( index_key, Reference),
> ...
> 
> This allows me to retrieve item(s) against an index_key nice and quickly:
> 
> ...
> recorded( index_key, Ref),
> recorded( _, Saved_data, Ref),
> ...
> 
> Is this safe? 
> 
> I suddenly got worried by your mention of garbage collection...but
> references have remained intact > so far in my experience!

Sure. DB references are guaranteed to be valid until they are erased or
until the session ends (i.e. they don't survive qsave_program/2 and
restore). The program heap (where these databases reside) is not garbage
collected. Normal garbage collection only affects the global and trail
stacks, atom garbage collection only atoms.

All should be fully transparent to the Prolog user as well as the
C-programmer using the C/C++ interfaces.  The only exception being that
references to atoms from C-code need to be locked/unlocked using
PL_(un)register_atom() under some (not very common) conditions.

> I had assumed this was OK because erase/1 requires a reference and 
> presumably a garbage collection > can happen anytime.

The other mail referred to term-references from the C-interface (term_t
objects). These are indirect handles to terms living on the global
stack.  Such references are scoped.

> Congratulations on a brilliant product, I hope to purchase a
> commercial license from SWI soon.

Thanks.  Paid licenses make it easier to actively develop SWI-Prolog!

	Regards --- Jan

