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