swarm-support
[Top][All Lists]
Advanced

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

Re: Have you ever seen a compiler error message like this?


From: glen e. p. ropella
Subject: Re: Have you ever seen a compiler error message like this?
Date: Fri, 7 Nov 1997 07:53:40 -0700

Paul Johnson writes:
 > Scott C. wins the prize. I had a typo in Makefile so Setter.o was
 > not being created.  In case you deleted the previous mail, you can
 > read below to see what a linker error is.

Cool.  I knew he would come in handy. [grin]

Benedikt correctly outlined the three possibilities.  I'd like to add
to what he said.

Benedikt Stefansson writes:
[newpos == IVar]
 > -makeProp: (dimarray *) x {
 > 
 >  newpos[0]= x[0] + 1;  //this would be embellished once I understood
 >  newpos[1]= x[1] + 1; //the passing of values.
 > 
 >  return self;
 > }

[newpos allocated beforehand]
 > -makeProp: (dimarray *) in to: (dimmarray *) out {
 >     out[0]=in[0]+1;
 >     out[1]=in[1]+1;
 > 
 >    return self;
 > }

[newpos allocated locally and preserved]
 > -(dimarray *) makeProp: (dimarray *) x {
 > 
 >      dimarray * newpos;
 > 
 >      newpos=calloc(2,sizeof(dimarray));
 > 
 >       newpos[0]= x[0] + 1;
 >       newpos[1]= x[1] + 1;
 > 
 >      return newpos;
 > }

The choice of which of these methods to use should be based on the
purpose of the "dimarray."  If it's purely internal to an object and
"makeProp" is called by the object on itself, then they're all fairly
equivalent; but I wouldn't recommend #3 because the allocation should
be done in an initialization method.  But, there's not much point in
using #2 if the object only calls this method on itself.

If the space is to be shared by other objects, then the IVar "newpos"
will be 'set' to point at an already allocated dimarray, which means
#3 is not the way to go.

So, if objects will be calling "makeProp" on *other* objects and the
"space" dimarray is shared by more than one object, I would use #2.
If the "space" dimarray is purely defined inside an object, I would
use #1, regardless of whether objects call each others' "makeProp".

For #3, this only seems reasonable for a proliferation of dimarrays.
It could lead to memory leaks.  But, one might either allocate the new
one and throw away the old one (very inefficient) or have need for
both the new one and the old one.  So, it's not unreasonable.  But! if
you're going to allocate memory, I'd suggest you use Zones rather than
a straight call to calloc. One of the following should suffice:

- (void *)      alloc: (size_t)size;
- (void)        free: (void *)aBlock;
- (void *)      allocBlock: (size_t)size;
- (void)        freeBlock: (void *)aBlock blockSize: (size_t)size;

glen
-- 
{glen e. p. ropella <address@hidden> |  Send lawyers, guns, and money!  }
{Hive Drone, SFI Swarm Project         |            Hail Eris!            }
{http://www.trail.com/~gepr/home.html  |               =><=               }

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