WeakArr.st
changeset 2091 c11bb3e29a1b
parent 1903 30c98b3377c5
child 2145 d243ffafeae3
equal deleted inserted replaced
2090:42653edf4cc5 2091:c11bb3e29a1b
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
       
    13 'From Smalltalk/X, Version:3.1.3 on 7-jan-1997 at 17:23:10'                     !
       
    14 
    13 Array subclass:#WeakArray
    15 Array subclass:#WeakArray
    14 	instanceVariableNames:'watcher dependents'
    16 	instanceVariableNames:'dependents'
    15 	classVariableNames:'RegistrationFailedSignal AlreadyInitialized'
    17 	classVariableNames:'RegistrationFailedSignal AlreadyInitialized'
    16 	poolDictionaries:''
    18 	poolDictionaries:''
    17 	category:'Collections-Arrayed'
    19 	category:'Collections-Arrayed'
    18 !
    20 !
    19 
    21 
    65     The reason for not sending messages directly from the VM is to make it 
    67     The reason for not sending messages directly from the VM is to make it 
    66     possible to run the finalization code at lower priority or from another class. 
    68     possible to run the finalization code at lower priority or from another class. 
    67     Also, as a side effect, it is possible to delay finalization by blocking 
    69     Also, as a side effect, it is possible to delay finalization by blocking 
    68     interrupts.
    70     interrupts.
    69 
    71 
    70     Notice, that there are currently two mechanisms by which a weakArray notifies
    72     A weakArray notifies its dependents via normal dependency notfications.
    71     its dependents: via normal dependency notfications and/or by sending an
       
    72     explicit message to a watcher object, which is found in an instvar of the
       
    73     WeakArray.
       
    74 
       
    75     Having two mechanisms here (i.e. watcher & dependent) is a historic leftover;
       
    76     I dont know, which of the two mechanisms will survive in the long run - 
       
    77     I started with the watcher, but now switch to dependencies since they seem 
       
    78     to offer more flexibility.
       
    79     You should NOT use the watcher mechanism; be prepared, that the watcher 
       
    80     mechanism may vanish in the future (i.e. use dependents for your applications).
       
    81 
    73 
    82     NOTICE: 
    74     NOTICE: 
    83         WeakArray handling adds some overhead to the VM 
    75         WeakArray handling adds some overhead to the VM 
    84         (each weakarray is scanned after each GC). 
    76         (each weakarray is scanned after each GC). 
    85         It is uncertain, if the current mechanism works well
    77         It is uncertain, if the current mechanism works well
    89     the oldSpace reclamation code - this would remove most of the overhead,
    81     the oldSpace reclamation code - this would remove most of the overhead,
    90     but will lead to much longer delayed finalization .... we will see.
    82     but will lead to much longer delayed finalization .... we will see.
    91 
    83 
    92 
    84 
    93     [instance variables:]
    85     [instance variables:]
    94 
       
    95         watcher                         if non-nil, gets informed via #informDispose
       
    96                                         that the weakArray has lost pointers.
       
    97 
    86 
    98         dependents                      get informed via #change notifiction 
    87         dependents                      get informed via #change notifiction 
    99                                         that the weakArray has lost pointers.
    88                                         that the weakArray has lost pointers.
   100                                         Having the dependents here is an optimization.
    89                                         Having the dependents here is an optimization.
   101 
    90 
   269 
   258 
   270 dependents:aCollection
   259 dependents:aCollection
   271     "set the dependents of the receiver"
   260     "set the dependents of the receiver"
   272 
   261 
   273     dependents := aCollection
   262     dependents := aCollection
   274 !
       
   275 
       
   276 watcher
       
   277     "return the watcher of the receiver.
       
   278      The watcher-stuff is a leftover from an old implementation 
       
   279      and will vanish soon"
       
   280 
       
   281     ^ watcher
       
   282 !
       
   283 
       
   284 watcher:anObject
       
   285     "set the watcher of the receiver.
       
   286      The watcher-stuff is a leftover from an old implementation 
       
   287      and will vanish soon"
       
   288 
       
   289     watcher := anObject
       
   290 ! !
   263 ! !
   291 
   264 
   292 !WeakArray methodsFor:'copying'!
   265 !WeakArray methodsFor:'copying'!
   293 
   266 
   294 postCopy
   267 postCopy
   639 ! !
   612 ! !
   640 
   613 
   641 !WeakArray methodsFor:'notification'!
   614 !WeakArray methodsFor:'notification'!
   642 
   615 
   643 lostPointer
   616 lostPointer
   644     "I lost a pointer; tell watcher and/or dependents.
   617     "I lost a pointer; tell dependents.
   645      This is sent from the finalization code in ObjectMemory."
   618      This is sent from the finalization code in ObjectMemory."
   646 
   619 
   647     watcher notNil ifTrue:[
       
   648         watcher informDispose
       
   649     ].
       
   650     dependents notNil ifTrue:[
   620     dependents notNil ifTrue:[
   651         self changed:#ElementExpired with:nil.
   621         self changed:#ElementExpired with:nil.
   652     ].
   622     ].
   653 
   623 
   654     "Modified: 18.10.1996 / 21:28:10 / cg"
   624     "Modified: 18.10.1996 / 21:28:10 / cg"
       
   625     "Modified: 7.1.1997 / 17:22:52 / stefan"
   655 ! !
   626 ! !
   656 
   627 
   657 !WeakArray class methodsFor:'documentation'!
   628 !WeakArray class methodsFor:'documentation'!
   658 
   629 
   659 version
   630 version
   660     ^ '$Header: /cvs/stx/stx/libbasic/Attic/WeakArr.st,v 1.36 1996-11-06 12:17:58 cg Exp $'
   631     ^ '$Header: /cvs/stx/stx/libbasic/Attic/WeakArr.st,v 1.37 1997-01-08 19:42:14 stefan Exp $'
   661 ! !
   632 ! !
   662 WeakArray initialize!
   633 WeakArray initialize!