Re: [q-lang-users] Libqint and the stability of qexps
Brought to you by:
agraef
From: John C. <co...@cc...> - 2006-06-06 15:13:32
|
Albert Graef scripsit: > Yes, they are. Expressions are never copied, always shared. And the > garbage collector will never move expressions around, it only adds them > to the freelist when they become inaccessible. Excellent. > Note that if you keep pointers to temporary Q expressions (i.e., with a > reference count of 0) in your Scheme data structures then those > expressions may well be garbage-collected at any time during an > evaluation. Good point. This by itself wouldn't be a problem, since the associations between Scheme objects and Q objects are only used when recursively decomposing the qexp and constructing the corresponding qsxp (Q-language S-expression). In this process, I never attempt to do anything with a saved qexp except compare it with a returned qexp, so if the saved qexp is garbage, no harm is done. The real danger is that a qexp formerly referred to may be discarded by Q and a newly created qexp may wind up at exactly the same C-level address, causing false positive matches. Because of this, I will be sure to qnewref() my qexps. > Therefore, to avoid nasty surprises, you should always count a reference > (qnewref) to Q expressions which are stored somewhere. Is it necessary to call qnewref() on each newly constructed qexp, or only on the top-level qexp? -- John Cowan co...@cc... http://ccil.org/~cowan Sound change operates regularly to produce irregularities; analogy operates irregularly to produce regularities. --E.H. Sturtevant, ca. 1945, probably at Yale |