<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Matthew Flatt schreef:
<blockquote cite="mid200511221430.jAMEU3dq029877@pegasus" type="cite">
<pre wrap="">Ok, but I'm still missing something, because I don't see how the table
accomplishes anything. In particular, ekeeping the key maintains the
mapping to the weak box, but it doesn't keep the weak box from getting
emptied.
</pre>
</blockquote>
Ok, another example session (see below). <br>
<br>
<i>"A <strong>weak box</strong> is similar to a normal box (see
section <a
href="http://download.plt-scheme.org/doc/mzscheme/mzscheme-Z-H-3.html#node_sec_3.10">3.10</a>),
but when the automatic memory manager can prove that the content
value of a weak box is only reachable via weak boxes, the content of
the weak box is replaced with <code class="scheme"><span
class="selfeval">#f</span></code>."<br>
</i><br>
As I see it, in the example below, a, b and c all point to the memory<br>
"contained" in the weak box. As long as a, b and c exist, the contents<br>
of the weak box will never be removed. And that is exactly what <br>
I want.<br>
<br>
You see, what happens is as follows:<br>
<br>
1. psearch actually does a RPC via TCP/IP on localhost, port 4001. <br>
telnetting on localhost port 4001 gives the following session:<br>
<br>
<tt>(OODB "LPW0251.strader.xs4all.nl" 0.1 "oodb-backend-sqli" 0.1 1)<br>
(search (all (illness-class-category)) ())(ok
((59872449310226502864700443097271<br>
illness-class-category)))<br>
<br>
</tt>2. The result: <tt>((59872449310226502864700443097271
illness-class-category))<br>
</tt>indicates that OID 59...271 is of class illness-class-category.
<br>
<br>
3. Next, an object of class illness-class-category is instantiated with
'from-oid OID. This instantiates<br>
a class illness-class-category with default parameters. <br>
<br>
4. Now I store (list OID) in the instantiated object and I put the
object in a weak box. The (list OID)<br>
of object I use as key in the hash table. <br>
<br>
5. When I retrieve another <tt>((59872449310226502864700443097271
illness-class-category))<br>
</tt>from the server, I first look for (list OID) in the hash table.
HEY, there's an object already there, I'll use<br>
this one instead of allocating a new one. <br>
<br>
Now, what I've effectivly reached, is that within the same running
instance of an application, two objects <br>
of the same OID, which are eq? in the object oriented database (OODB)
I've created, are also eq? in<br>
the running instance. And that's just what I wanted. Thanks to Eli's
input!<br>
<br>
<tt>> (require "proos.scm")<br>
> (require "oodb-ci.scm")<br>
> (oodb-ci-initialize "localhost" "hans" "" 4001)<br>
#t<br>
</tt><tt>> (require "zk-classes.scm")<br>
> (define a (car (psearch (all illness-class-category))))<br>
PROOS-STORE: 59872449310226502864700443097271 #f #f <br>
PROOS-STORE: 59872449310226502864700443097271 #roos <br>
> (define b (car (psearch (all illness-class-category))))<br>
PROOS-STORE: 59872449310226502864700443097271 #<weak-box> #roos <br>
> b<br>
#roos<br>
> (eq? a b)<br>
#t<br>
> (-> a name)<br>
"ok"<br>
> (-> b name)<br>
"ok"<br>
> (-> a name "new name")<br>
ok-put!<br>
> (-> b name)<br>
"new name"<br>
> (collect-garbage)<br>
> (define b (car (psearch (all illness-class-category))))<br>
PROOS-STORE: 59872449310226502864700443097271 #<weak-box> #roos <br>
> (collect-garbage)<br>
> (define b (car (psearch (all illness-class-category))))<br>
PROOS-STORE: 59872449310226502864700443097271 #<weak-box> #roos <br>
> (collect-garbage)<br>
> (define c (car (psearch (all illness-class-category))))<br>
PROOS-STORE: 59872449310226502864700443097271 #<weak-box> #roos <br>
> c<br>
#roos<br>
> (set! a 0)(set! b 0)(set! c 4)<br>
> > > (define c (car (psearch (all illness-class-category))))<br>
PROOS-STORE: 59872449310226502864700443097271 #<weak-box> #roos <br>
> c<br>
#roos<br>
> (-> c name)<br>
"new name"<br>
(-> c illness-classes)<br>
PROOS-STORE: 163698054800566253127307108927946 #f #f <br>
PROOS-STORE: 163698054800566253127307108927946 #roos <br>
PROOS-STORE: 163698054800566253127307108927945 #f #f <br>
PROOS-STORE: 163698054800566253127307108927945 #roos <br>
PROOS-STORE: 163698054800566253127307108927944 #f #f <br>
PROOS-STORE: 163698054800566253127307108927944 #roos <br>
PROOS-STORE: 134167358730453000620204068929124 #f #f <br>
PROOS-STORE: 134167358730453000620204068929124 #roos <br>
PROOS-STORE: 132069009480453002472005822925980 #f #f <br>
PROOS-STORE: 132069009480453002472005822925980 #roos <br>
PROOS-STORE: 132069009480453002472005822925979 #f #f <br>
PROOS-STORE: 132069009480453002472005822925979 #roos <br>
PROOS-STORE: 132069009480453002472005822925978 #f #f <br>
PROOS-STORE: 132069009480453002472005822925978 #roos <br>
PROOS-STORE: 101069891380339751816804499004492 #f #f <br>
PROOS-STORE: 101069891380339751816804499004492 #roos <br>
PROOS-STORE: 68254699550226382758901006667984 #f #f <br>
PROOS-STORE: 68254699550226382758901006667984 #roos <br>
PROOS-STORE: 63721520500226501175203246565420 #f #f <br>
PROOS-STORE: 63721520500226501175203246565420 #roos <br>
(#roos #roos #roos #roos #roos #roos #roos #roos #roos #roos)<br>
> (define b (car (-> c illness-classes)))<br>
PROOS-STORE: 163698054800566253127307108927946 #<weak-box> #roos
<br>
PROOS-STORE: 163698054800566253127307108927945 #<weak-box> #roos
<br>
PROOS-STORE: 163698054800566253127307108927944 #<weak-box> #roos
<br>
PROOS-STORE: 134167358730453000620204068929124 #<weak-box> #roos
<br>
PROOS-STORE: 132069009480453002472005822925980 #<weak-box> #roos
<br>
PROOS-STORE: 132069009480453002472005822925979 #<weak-box> #roos
<br>
PROOS-STORE: 132069009480453002472005822925978 #<weak-box> #roos
<br>
PROOS-STORE: 101069891380339751816804499004492 #<weak-box> #roos
<br>
PROOS-STORE: 68254699550226382758901006667984 #<weak-box> #roos <br>
PROOS-STORE: 63721520500226501175203246565420 #<weak-box> #roos <br>
> (proos-store->list)<br>
(((163698054800566253127307108927944) #<weak-box>)
((101069891380339751816804499004492) #<weak-box>)
((134167358730453000620204068929124) #<weak-box>)
((68254699550226382758901006667984) #<weak-box>)
((132069009480453002472005822925979) #<weak-box>)
((132069009480453002472005822925980) #<weak-box>)
((59872449310226502864700443097271) #<weak-box>)
((132069009480453002472005822925978) #<weak-box>)
((63721520500226501175203246565420) #<weak-box>)
((163698054800566253127307108927946) #<weak-box>)
((163698054800566253127307108927945) #<weak-box>))<br>
> (collect-garbage)<br>
> (proos-store->list)<br>
(((59872449310226502864700443097271) #<weak-box>)
((163698054800566253127307108927946) #<weak-box>))<br>
> (set! c 0)<br>
> (proos-store->list)<br>
(((59872449310226502864700443097271) #<weak-box>)
((163698054800566253127307108927946) #<weak-box>))<br>
> (collect-garbage)<br>
> (proos-store->list)<br>
(((163698054800566253127307108927946) #<weak-box>))<br>
> b<br>
#roos<br>
(-> b poid)<br>
163698054800566253127307108927946<br>
> (set! b 2)<br>
> (collect-garbage)<br>
> (proos-store->list)<br>
()<br>
> <br>
</tt><br>
**********************************************************<br>
as for the class definitions<br>
**********************************************************<br>
<br>
<tt>(def-pclass <br>
(this (illness-class-category . args))<br>
(default)<br>
(supers)<br>
(private)<br>
(persistent<br>
name<br>
z-order<br>
)<br>
(public<br>
<br>
(define (illness-classes)<br>
(psearch (= (illness-class category-oid) (poid this))))<br>
<br>
(define (add-illness-class obj)<br>
(-> obj category-oid (poid this)))<br>
<br>
)<br>
(constructor)<br>
)<br>
<br>
<br>
(def-pclass<br>
(this (illness-class . args))<br>
(default)<br>
(supers)<br>
(private)<br>
(persistent<br>
_category<br>
category-oid<br>
name<br>
color-fg<br>
color-bg<br>
font<br>
)<br>
(public<br>
(define (category . cat)<br>
(if (not (null? cat))<br>
(begin<br>
(-> this _category (car cat))<br>
(-> (car cat) add-illness-class this)))<br>
(-> this _category))<br>
<br>
)<br>
(constructor)<br>
)<br>
</tt><br>
<br>
<blockquote cite="mid200511221430.jAMEU3dq029877@pegasus" type="cite">
<pre wrap="">
Are `a' and `b' keys here?
</pre>
</blockquote>
No, the're the (Persistent) ROOS objects.<br>
<blockquote cite="mid200511221430.jAMEU3dq029877@pegasus" type="cite">
<pre wrap="">
Ok, but is what's in the weak box --- an object or #f?
</pre>
</blockquote>
As can be seen from the previous section. Still the object.<br>
<blockquote cite="mid200511221430.jAMEU3dq029877@pegasus" type="cite">
<pre wrap="">
Looking back at your problem description, maybe what I'm missing is
that it's ok for for the weak box to be emptied, because this table
implements a cache?
</pre>
</blockquote>
Well it sort of creates a cache. As long as there are "living" objects
of a certain OID, the<br>
cache won't be collected. When all objects of a certain OID cease to
exist, it is collected.<br>
<blockquote cite="mid200511221430.jAMEU3dq029877@pegasus" type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">
<pre wrap="">However when I don't use the (list) around the oid, It won't work.
Isn't there a way without the 'equal property on the hash table?
</pre>
</blockquote>
</blockquote>
Ok, but then I'll have to convert a number to a symbol each time. I
wonder what is more expensive?<br>
Note that the numbers I use are fairly large. Doesn't that open
possibilities?<br>
<blockquote cite="mid200511221430.jAMEU3dq029877@pegasus" type="cite">
<pre wrap="">Using symbols instead of numbers might be the right trade-off. Symbols
are allocated and collected, like lists, but they are also interned,
like small integers.
Matthew
</pre>
</blockquote>
Thanks,<br>
<br>
Hans<br>
<br>
</body>
</html>