gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz ./TODO gzz/mem/MemoryPartitioner.java test/...


From: Tuomas J. Lukka
Subject: [Gzz-commits] gzz ./TODO gzz/mem/MemoryPartitioner.java test/...
Date: Wed, 08 Jan 2003 10:08:19 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Tuomas J. Lukka <address@hidden>        03/01/08 10:08:19

Modified files:
        .              : TODO 
        gzz/mem        : MemoryPartitioner.java 
        test/gzz/mem   : partition.test 

Log message:
        Cleaning, algorithm adj

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/TODO.diff?tr1=1.494&tr2=1.495&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/mem/MemoryPartitioner.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/test/gzz/mem/partition.test.diff?tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: gzz/TODO
diff -u gzz/TODO:1.494 gzz/TODO:1.495
--- gzz/TODO:1.494      Wed Jan  8 03:44:26 2003
+++ gzz/TODO    Wed Jan  8 10:08:19 2003
@@ -252,6 +252,7 @@
            - load in separate thread
            - discard high-rez images when not in use
            - use lower resolution first, lazily load better
+       - keymapping in both directions
        - xupdf: distorted multi-page PDF view with xu links
            - overall goal: USEFUL when article writing starts
            - multiple instances of same cell visible as a buoy --> keys?
Index: gzz/gzz/mem/MemoryPartitioner.java
diff -u gzz/gzz/mem/MemoryPartitioner.java:1.4 
gzz/gzz/mem/MemoryPartitioner.java:1.5
--- gzz/gzz/mem/MemoryPartitioner.java:1.4      Wed Jan  8 09:04:14 2003
+++ gzz/gzz/mem/MemoryPartitioner.java  Wed Jan  8 10:08:19 2003
@@ -11,7 +11,7 @@
  * MemoryConsumers.
  */
 public class MemoryPartitioner {
-    public static boolean dbg = true;
+    public static boolean dbg = false;
     static final void pa(String s) { System.out.println(s); }
 
     /** The amount of memory reserved to MemoryConsumers.
@@ -144,9 +144,9 @@
            while(true) {
                if(!keepRepartitioner) return;
                try {
-                   if(dbg) pa("Going to rerate\n");
+                   if(dbg) pa("Going to rerate");
                    rerate();
-                   if(dbg) pa("rerated, sleeping\n");
+                   if(dbg) pa("rerated, sleeping");
                    Thread.sleep(10);
                } catch(Exception e) { 
                    ZZLogger.exc(e, "gzz.mem.MemoryPartitioner thread!");
@@ -158,41 +158,50 @@
     /** Reallocate all memory.
      */
     private void rerate() {
+       // Maximum importance found
+       float maximportance = 0;
+       // Sum of maxbytes with priority 1
+       int sum1 = 0;
+       for(Iterator i = consumer2record.keySet().iterator(); i.hasNext(); ) {
+           MemoryConsumer cons = (MemoryConsumer)i.next();
+           ConsumerRecord rec = (ConsumerRecord)consumer2record.get(cons);
+           rec.bgUpdate();
+           if(rec.curImportance > maximportance) maximportance = 
rec.curImportance;
+           if(rec.curImportance == 1)
+               sum1 += cons.getMaxBytes(rec.curQuality);
+       }
+       if(sum1 > memory) {
+           // Problem! Not enough memory for all 1-importances
+           // - fill from start as many as we can
+           int left = memory;
+           for(Iterator i = consumer2record.keySet().iterator(); i.hasNext(); 
) {
+               MemoryConsumer cons = (MemoryConsumer)i.next();
+               ConsumerRecord rec = (ConsumerRecord)consumer2record.get(cons);
+               if(rec.curImportance == 1) 
+                   left = rec.maximum(cons, left);
+               else 
+                   rec.fit(cons, 0);
+           }
+           return;
+       }
+       if(maximportance <= 0) return;
+       // Else, find a good exponent
        for(int round = 0; ; round++) {
-           // Sum of maxbytes with priority 1
-           int sum1 = 0;
            // Sum of maxbytes multiplied with priority^round
            int sumReduced = 0;
            if(dbg) pa("Rerate round "+round);
            for(Iterator i = consumer2record.keySet().iterator(); i.hasNext(); 
) {
                MemoryConsumer cons = (MemoryConsumer)i.next();
                ConsumerRecord rec = (ConsumerRecord)consumer2record.get(cons);
-               if(round == 0) rec.bgUpdate();
                float imp = 0;
                if(rec.curImportance > 0)
-                   imp = (float)Math.pow(rec.curImportance, round);
+                   imp = (float)Math.pow(rec.curImportance/maximportance, 
round);
                else if(round == 0)
                    imp = 1;
                int byt = cons.getMaxBytes(rec.curQuality);
-               if(rec.curImportance == 1)
-                   sum1 += byt;
                sumReduced += (int)(imp * byt);
            }
            if(dbg) pa("Counted: "+sum1+" "+sumReduced);
-           if(sum1 > memory) {
-               // Problem! Not enough memory for all 1-importances
-               // - fill from start as many as we can
-               int left = memory;
-               for(Iterator i = consumer2record.keySet().iterator(); 
i.hasNext(); ) {
-                   MemoryConsumer cons = (MemoryConsumer)i.next();
-                   ConsumerRecord rec = 
(ConsumerRecord)consumer2record.get(cons);
-                   if(rec.curImportance == 1) 
-                       left = rec.maximum(cons, left);
-                   else 
-                       rec.fit(cons, 0);
-               }
-               return;
-           }
            if(sumReduced <= memory) {
                // Hey, now it fits!
                //
@@ -201,7 +210,7 @@
                    ConsumerRecord rec = 
(ConsumerRecord)consumer2record.get(cons);
                    float imp = 0;
                    if(rec.curImportance > 0)
-                       imp = (float)Math.pow(rec.curImportance, round);
+                       imp = (float)Math.pow(rec.curImportance/maximportance, 
round);
                    else if(round == 0)
                        imp = 1;
                    int byt = cons.getMaxBytes(rec.curQuality);
Index: gzz/test/gzz/mem/partition.test
diff -u gzz/test/gzz/mem/partition.test:1.2 gzz/test/gzz/mem/partition.test:1.3
--- gzz/test/gzz/mem/partition.test:1.2 Wed Jan  8 09:04:14 2003
+++ gzz/test/gzz/mem/partition.test     Wed Jan  8 10:08:19 2003
@@ -1,9 +1,10 @@
+from __future__ import nested_scopes
 #(c): Tuomas J. Lukka
 
 import gzz
 import java
 
-# room for 2, not 3
+pool = gzz.mem.MemoryPartitioner(500)
 
 class Reserver(gzz.mem.MemoryConsumer):
     def __init__(self):
@@ -19,22 +20,22 @@
     def getQuality(self):
        return self.qual
 
+def waitFor(f):
+    for i in range(0,20):
+       java.lang.Thread.sleep(50)
+       if f():
+           pool.stop()
+           return
+    pool.stop()
+    failUnless(0)
+    
+
 def testLoading1():
     """Test that one block does get loaded.
-
-    fail: *
     """
-    pool = gzz.mem.MemoryPartitioner(500)
     b = Reserver()
 
-    pool.request(b, 1, 1, None)
+    pool.request(b, .5, 1, None)
 
-    for i in range(0,100):
-       java.lang.Thread.sleep(50)
-       print "Reserved: ",b.rese
-       if b.rese == 230:
-           pool.stop()
-           return
-    pool.stop()
-    failUnless(0)
+    waitFor(lambda: b.rese == 230)
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]