Re: About node references
Dimitre Novatchev <[email protected]> Mon, 15 Dec 2008 15:31:26 -0800 (PST)
| Newsgroups | gmane.text.xml.xslt.extensions |
|---|---|
| Message-ID | <[email protected]> |
> > I would like to add the function I already proposed: > > > > string refCopy(ref) > > > > which is to be used any time we want to copy/save a ref. > > Dereferencing a copied/saved ref will be guaranteed to be > > successful only for strings obtained from refCopy(). This > > eliminates the "leakage" problem. > > Sorry, I absolutely don't understand how you see this working. > > When you say a "string obtained from refCopy()", I'm not sure what you mean. > Would it also work on > > codepoints-to-string(string-to-codepoints(refCopy(x))? > I realize that until now I have presented this idea only very vaguely. Here is a first try at a more consistent presentation. A "Ref" is an object that has two parts: a reference (memory reference) and an associated string key. So, a Ref can be represented by the pair: (strKey, memRef) We have the following basic Ref - related operations: String xx:getKey(Ref ref) produces a storable representation of this Ref Ref xx:getRef(String key) from a stored representation of a Ref produces the complete Ref object. (Hashtable implementable). If a Ref object must be destroyed (as part of its holder going out of scope), it is deleted by key from the (centralized) hashtable. The following identities should hold: xx:getRef(xx:getKey(ref)) = ref and xx:getKey(xx:getRef(key)) = key Additionally, we have the function: Ref xx:copyRef(Ref ref1) From an object ref1 = (strKey1, memRef1) produces an object ref 2 = (strKey2, memRef2), such that memRef2 = memRef1 The important thing here is that we have created a second memRef to the same item. If now ref1 goes out of scope and is destroyed, ref2 may still be in scope and thus its memRef will ensure the item being referenced is not going to be garbage-collected. String xx:copyRef(String strKey1) = xx:getKey(xx:copyRef(xx:getRef(strKey1))) Gets ref1 from its key, then makes a ref2 as above, then produces the key for ref2. To summarise, using the result ref2 of the copyRef(ref1) function guarantees that we have an independent ref to the same item, that will remain valid as long as we are in scope independent of the lifetime of the original ref1. Also, when all Refs to an item are destroyed, this item can be garbage-collected, thus no "leakage" is to occur due to using Refs I hope this definition makes more sense now? Cheers, Dimitre