WeakArr.st
changeset 95 d22739a0c6e9
parent 88 81dacba7a63a
child 159 514c749165c3
--- a/WeakArr.st	Fri Aug 05 03:03:07 1994 +0200
+++ b/WeakArr.st	Fri Aug 05 03:03:10 1994 +0200
@@ -20,6 +20,8 @@
 WeakArray comment:'
 COPYRIGHT (c) 1991 by Claus Gittinger
               All Rights Reserved
+
+$Header: /cvs/stx/stx/libbasic/Attic/WeakArr.st,v 1.5 1994-08-05 01:03:04 claus Exp $
 '!
 
 !WeakArray class methodsFor:'documentation'!
@@ -40,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/Attic/WeakArr.st,v 1.4 1994-06-02 16:22:45 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/WeakArr.st,v 1.5 1994-08-05 01:03:04 claus Exp $
 "
 !
 
@@ -50,7 +52,19 @@
     objects, references by WeakArrays will NOT keep an object from dying.
     Instead, whenever an object kept in a WeakArray dies, its entry is nilled,
     and the WeakArray informed by the storage manager. 
-    This is done by sending a #disposeInterrupt to the weakArray.
+    You can use WeakArrays to track disposal of objects which keep external
+    world resources. For example, FileStreams must close their underlying
+    file when disposed (otherwise you would run out of filedescriptors).
+    This can be done by keeping the FileStream objects in a weakArray, and
+    keep a parallel array of filedescriptors. Whenever a fileStream gets
+    free, search both arrays for an index where the stream is nil, but the
+    filedescriptor is non-nil. Then close that file, and nil the filedescriptor
+    entry.
+
+    Another application is caching of data - keep it in a weakArray, so the
+    data in that cache will not be unreclaimable due to being cached.
+    (for example, the ResourcePack class uses a WeakArray to cache recently
+    used resource data for a while).
 
     This interrupt is cought here and informs the watcher and, if there is
     a dependent, this one gets informed as well (I dont know, which of the
@@ -64,18 +78,20 @@
 !WeakArray class methodsFor:'instance creation'!
 
 new:size
-    "return a new weakArray with size slots.
-     This is a kludge: would like to set WEAK-flag in class
-     initialize method, but no order of class-init is defined ...
-     (therefore it could happen, that a WeakArray is used by other
-      class inits before this init is evaluated. To avoid this,
-      the WEAK bit in the class is set when the first WeakArray is 
-      created)"
+    "return a new weakArray with size slots"
 
     |newArray|
 
-    self flags:5.   "having a constant 5 here is very bad"
+    "This is a kludge: I would like to set WEAK-flag in the classes
+     initialize method, but no order of class-init is defined ...
+     Therefore it could happen, that a WeakArray is used by other
+     class inits BEFORE this initialize is evaluated. To avoid this,
+     the WEAK bit in the class is set when the first WeakArray is 
+     created."
+
+    self flags:(Behavior flagWeakPointers).
     ObjectMemory disposeInterruptHandler:self.
+
     newArray := self basicNew:size.
 %{
     OBJ ok;