Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: Allocator/BestFitStrategy.java


1   // BestFitStrategy.java, created Mon Mar 17  2:03:41 2003 by laudney
2   // Copyright (C) 2001-3 laudney <laudney@acm.org>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package Allocator;
5   
6   import java.util.Collection;
7   import java.util.TreeSet;
8   
9   /**
10   * Best Fit Strategy
11   *
12   * @author laudney <laudney@acm.org>
13   * @version $Id: BestFitStrategy.java,v 1.3 2003/05/12 10:04:52 joewhaley Exp $
14   */
15  public class BestFitStrategy implements FreeMemStrategy {
16      private TreeSet freePool;
17  
18      public BestFitStrategy() {
19          freePool = new TreeSet(new MemUnitComparator());
20      }
21  
22      public void addFreeMem(MemUnit unit) {
23          freePool.add(unit);
24      }
25  
26      public void addCollection(Collection c) {
27          freePool.addAll(c);
28      }
29  
30      public MemUnit getFreeMem(int size) {
31          if (false) {
32              MemUnit target = new MemUnit(null, size);
33              return (MemUnit) (freePool.tailSet(target).first());
34          } else {
35              // FIXME: circular dependency. the allocation of MemUnit above
36              // calls the allocator which calls getFreeMem.
37              return null;
38          }
39      }
40  }