author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 26 Apr 2010 19:26:38 +0100 | |
branch | jv |
changeset 17761 | b0e5971141bc |
parent 17711 | 39faaaf888b4 |
child 17845 | 7e0cfaac936d |
permissions | -rw-r--r-- |
4434 | 1 |
" |
2 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
4434 | 13 |
|
14 |
Registry subclass:#CachingRegistry |
|
15 |
instanceVariableNames:'keptReferences cacheSize' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'System-Support' |
|
19 |
! |
|
20 |
||
21 |
!CachingRegistry class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
A CachingRegistry behaves generally like a registry; |
|
41 |
However, it keeps hard references to the last n registered objects, |
|
42 |
preventing them from being garbage collected (and finalized). |
|
43 |
This is useful for resources, which do not cost too much memory, |
|
44 |
but are expensive to allocate - a special canditate of this kind are |
|
45 |
XFonts. With a CachingRegistry, fonts are kept a bit longer alive |
|
46 |
and can therefore often be reused - even if temporarily unreferenced. |
|
47 |
||
48 |
This is kind of experimental. |
|
49 |
||
50 |
||
51 |
[author:] |
|
52 |
Claus Gittinger (cg@exept) |
|
53 |
||
54 |
[see also:] |
|
55 |
||
56 |
[instance variables:] |
|
57 |
keptObjects Collection hard referenced objects |
|
58 |
cacheSize Integer number of hard references |
|
59 |
||
60 |
[class variables:] |
|
61 |
" |
|
62 |
! ! |
|
63 |
||
64 |
!CachingRegistry methodsFor:'private'! |
|
65 |
||
66 |
cacheSize:aNumber |
|
67 |
keptReferences := OrderedCollection new:aNumber. |
|
68 |
cacheSize := aNumber. |
|
69 |
! ! |
|
70 |
||
71 |
!CachingRegistry methodsFor:'registering objects'! |
|
72 |
||
73 |
register:anObject as:aHandle |
|
74 |
keptReferences removeIdentical:anObject ifAbsent:nil. |
|
75 |
keptReferences addLast:anObject. |
|
76 |
keptReferences size > cacheSize ifTrue:[ |
|
77 |
keptReferences removeFirst. |
|
78 |
]. |
|
79 |
super register:anObject as:aHandle. |
|
80 |
! |
|
81 |
||
82 |
repairTally |
|
83 |
keptReferences := OrderedCollection new:cacheSize. |
|
84 |
super repairTally. |
|
85 |
! |
|
86 |
||
87 |
unregister:anObject atIndex:index |
|
88 |
keptReferences removeIdentical:anObject ifAbsent:nil. |
|
89 |
super unregister:anObject atIndex:index. |
|
90 |
! ! |
|
91 |
||
92 |
!CachingRegistry class methodsFor:'documentation'! |
|
93 |
||
94 |
version |
|
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
95 |
^ '$Id: CachingRegistry.st 10517 2010-04-26 18:26:38Z vranyj1 $' |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
96 |
! |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
97 |
|
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
98 |
version_SVN |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
99 |
^ '$Id: CachingRegistry.st 10517 2010-04-26 18:26:38Z vranyj1 $' |
4434 | 100 |
! ! |