swarm-support
[Top][All Lists]
Advanced

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

am I wasting memory?


From: Paul E. Johnson
Subject: am I wasting memory?
Date: Fri, 19 Jun 1998 14:33:32 -0500 (CDT)

Please pardon me for asking such an obvious question, but since I've
got no colleagues to talk to about ojb-c, sometimes I just need to ask.

I have agents that have objects inside them.

In modelswarm, I have (what I now understand to be) the usual approach
where the agents are created in a loop and their parameters are created
and then passed into them with set methods. 

 Since one of the parameters I need to set is inside
an object, I have a set method that takes an object as a parameter.
here is a code snip (from inside the loop that creates agents)
       Recruiter * recruiter;
       PolicyPoint * aPosition;
       recruiter = [Recruiter createBegin: [self getZone]];
       [recruiter setWorld: world];
       recruiter = [recruiter createEnd];        

      aPosition=[PolicyPoint createBegin:[self getZone]];
      [aPosition setWorld: world];
      aPosition = [aPosition createEnd];  
   
      aPosition= [self createRandomPosition];
 
       [recruiter setInitialPosition: aPosition];   
       [recruiter setInitialDirection: initialDirection];
       [recruiter setWidthOfSearch: widthOfSearch];
 
       [recruiterList addLast: recruiter];

The loop creates an agent "Recruiter" and an object "aPosition"
which is then passed into
Recruiter.  Inside the Recruiter.m file, there is a create statement
for the object where "aPosition" gets passed into, and the code works
as far as I can see.

The question is am I wasting memory inside this loop recreating this
object aPosition over and over again?  Each time it steps, it is 
allocating temporary space for aPosition, right.  Are those spaces
being added up and wasted?  Is this the kind of place where I need
to use the drop command?

Or would I be better off putting aPosition as an object inside ModelSwarm,
and then each time through the loop I could just set new values inside
it and pass it to the Recruiter. That way, I'd only have one object
sitting around.

Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
University of Kansas                  Office: (913) 864-9086
Lawrence, Kansas 66045                FAX: (913) 864-5700


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