swarm-support
[Top][All Lists]
Advanced

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

Re: Java-Swarm questions


From: Marcus G. Daniels
Subject: Re: Java-Swarm questions
Date: 31 Dec 2000 19:03:46 -0800
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "PJ" == Paul E Johnson <address@hidden> writes:

PJ>   cell = *discrete2dSiteAt(lattice, offsets, x, y);

PJ> If in Java I subclass from Grid2d, I don't see how I can use this.

That macro won't work since you don't have access to the ivars and no
pointers.  You could get something with close to that kind of
performance by writing a Grid2d using Java arrays and compiling it with an
ahead-of-time compiler like gcj with bounds validation disabled.  IIRC,
I did most of those things in the code for SwarmFest 2000 performance talk.

Anyway, my advice is to write the code in the easiest way and then
profile it to see if using the getObjectAtX:Y: calls are actually a
bottleneck.

PJ> Aren't we relying on the garbage collector for an awful lot of help?

Yes!

PJ> 3. I understand from Marcus's example code the procedure to create
PJ> an instance of an objc class that requries the
PJ> createBegin/createEnd routine.  I can manage that.  I can't
PJ> understand how to create subclasses of such things, however.  

Here's an example.  It does need the current snapshots, but that
is because of this particular example, not because of subclassing itself.

import swarm.Globals;
import swarm.SwarmEnvironmentC;
import swarm.SwarmEnvironmentCImpl;
import swarm.SwarmEnvironmentImpl;
import swarm.defobj.Arguments;
import swarm.defobj.ArgumentsC;
import swarm.defobj.ArgumentsCImpl;
import swarm.defobj.ArgumentsImpl;
import swarm.defobj.Zone;

class MyArgumentsCImpl extends ArgumentsCImpl {
  MyArgumentsCImpl (Arguments arg) {
    super (arg);
  }
  
  public Object setArgc$Argv (int argc, String argv[]) {
    return super.setArgc$Argv (argc, argv);
  }
 
  public int parseKey$arg (int key, String arg) {
    if (super.parseKey$arg (key, arg) != 0) {
      if (key == (int) 'M') {
        ((MyArgumentsImpl) nextPhase).arg = arg;
      }
    }  
    return 0;
  }
}

class MyArgumentsImpl extends ArgumentsImpl {
  String arg;

  MyArgumentsImpl () {
    super ();
  }
}


public class TestArguments {
  static void main (String args[]) {
    Zone aZone = Globals.env.globalZone;
    
    ArgumentsC argumentsC = new MyArgumentsCImpl (new MyArgumentsImpl ());
    MyArgumentsImpl arguments;

    int i, len = args.length;
    String argv[] = new String[1 + len];

    argv[0] = "TestArguments";

    for (i = 0; i < len; i++)
      argv[1 + i] = args[i];

    argumentsC.createBegin (aZone);
    argumentsC.setAppName (argv[0]);
    argumentsC.setArgc$Argv (len + 1, argv);
    argumentsC.setAppModeString ("default");
    argumentsC.setBugAddress ("address@hidden");
    argumentsC.setVersion ("0.0");
      
    argumentsC.addOption$key$arg$flags$doc$group ("myarg", (int) 'M', 
"argvalue", 0, "My Argument", 0);
    arguments = (MyArgumentsImpl) argumentsC.createEnd ();

    Globals.envC.setArguments (arguments);
    Globals.envC.createEnd ();
    
    System.out.println (arguments.arg);
  }
}


                  ==================================
   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]