swarm-support
[Top][All Lists]
Advanced

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

Re: Sharing variables.


From: Fabio Mascelloni
Subject: Re: Sharing variables.
Date: Thu, 04 Mar 1999 11:05:02 +0100


Eric Werk wrote:

>
> You have the variable you want to share in the class you want to give
> write access, for eksample in Modelswarm, and then you implement a
> method (in ModelSwarm) to read the variable. Here is an eksample:
>
> @interface ModelSwarm: Swarm
> {
>    int  shared;
> }
> - (int) getShared;
> @end;
>
> @implementation ModelSwarm
> - (int) getShared
> {
>    return shared
> }
> @end;
>
> Then you let all your Agents have a reference to the ModelSwarm, that
> you have to initialize when you create the Agent objects
>
> @interface Agent: Swarm
> {
>    id modelSwarm;
> }
> - initModel: aModelSwarm;
>
> and then you can read the shared variable with
> [modelSwarm getShared];
>
> /Eric Werk
>

This's a good idea,but unfortunately the shared variables are all matrixes
that are heavely used by each agent.In each step of simulation all the
agents have to traverse all the rows of those matrixes.Wouldn't it be an
excessive overhead to call every time a method on the ModelSwarm to get
the needed row of each matrix?
Then I was thinking about declaring these matrixes @public in ModelSwarm's
interface and the acces their rows as a C structure ,i.e. modelSwarm->row.

I tried to do this way modifying the simpleObserverSwarm2 to make each bug
print a string declared @public in ModelSwarm  application,but it seems to
crash it.Is the latter method correct?

Fabio.



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