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