swarm-support
[Top][All Lists]
Advanced

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

Re: Swarm RPMS ahead of tornado!


From: Myriam Abramson
Subject: Re: Swarm RPMS ahead of tornado!
Date: 12 Sep 2001 15:42:22 -0400
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.3

> So, this program leaks memory for you?

No ... but this one does. Maybe I'm not deallocating something right. 


import java.util.*;

import swarm.objectbase.VarProbe;
import swarm.objectbase.MessageProbe;
import swarm.objectbase.EmptyProbeMap;
import swarm.objectbase.EmptyProbeMapImpl;
import swarm.objectbase.ProbeMap;
import swarm.Globals;
import swarm.defobj.Zone;
import swarm.defobj.Copy;

import swarm.objectbase.SwarmObjectImpl;

public class ProbeMapTest extends SwarmObjectImpl implements Comparable {
  public int points;
  public int cost;
  Random rand = new Random();
  MyProbeMap pm;

  ProbeMapTest (Zone azone) {
    points = rand.nextInt();
    cost = rand.nextInt();
    pm =  new MyProbeMap (azone, getClass());
  }

 class MyProbeMap extends EmptyProbeMapImpl {
                                     
  private VarProbe probeVariable (String name) {
      VarProbe varProbe = null;
      Class baseClass = getProbedClass();
      do {
        varProbe = 
          Globals.env.probeLibrary.getProbeForVariable$inClass
          (name, baseClass);
        baseClass = baseClass.getSuperclass();
      } while (varProbe == null && baseClass != null);
      return varProbe;
    }

    private void addVar(String name) {
      addProbe (probeVariable (name));
    }


    public MyProbeMap (Zone aZone, Class aClass) {
      super (aZone, aClass);
      addVar ("points");
      addVar ("cost");
    }

   public void varProbesDrop() {
     getProbeForVariable("points").drop();
     getProbeForVariable("cost").drop();
   }
  }

  public int compareTo (Object o) {
    ProbeMapTest obj = (ProbeMapTest) o;
    return (cost - obj.cost);
  }

  static void main (String args[]) {
    Globals.env.initSwarm ("ProbeMapTest", "address@hidden", "0.0", args);
    for (int i=0;i<100000;i++)
      {
        ProbeMapTest tmap = new ProbeMapTest (Globals.env.globalZone);
        tmap.pm.varProbesDrop();
        tmap.pm.drop();
        // tmap.drop();
        // I get an error on the line above
      }
  }
}

-- 

                                    myriam

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

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