Complete.Org: Mailing Lists: Archives: freeciv-ai: May 2002:
[freeciv-ai] Re: [Freeciv-Dev] Re: [RFC] Path finding interface #9

[freeciv-ai] Re: [Freeciv-Dev] Re: [RFC] Path finding interface #9

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv development list <freeciv-ai@xxxxxxxxxxx>
Subject: [freeciv-ai] Re: [Freeciv-Dev] Re: [RFC] Path finding interface #9
From: Per I Mathisen <per@xxxxxxxxxxx>
Date: Sun, 26 May 2002 18:14:15 +0200 (MEST)

On Sat, 25 May 2002, Raimar Falke wrote:
> > Also, even though this is a more dangerous way to code, please make these
> > functions give pointers to allocated structures as return values instead
> > of passing pointers to existing structures by reference.
> No. Either the pf_* functions allocate the space (and the callers
> frees it. This malloc/free is unnecessary and will eat CPU cycles) or
> the pf_* functions have static variables (which we want to avoid too
> since. Look at the current warmap code).

Yes, I want the pf_* functions to allocate the space. It won't eat much
CPU cycles compared to what else goes on in these functions, but it makes
the code much more readable.

> > ie
> >     struct pf_path path;
> >     ...
> >     pf_get_path(map,x,y,path);
> >     ...
> >     pf_get_path(map,x,y,path);
> So what? path will deallocated if we leave to scope.

That is beside the point. By looking at the above code alone, you cannot
tell that 1) "path" is changed in pf_get_path, and 2) the contents of
"path" passed to pf_get_path is irrelevant.

If you do

        path = pf_get_path(map,x,y);

these two points are apparent from a quick reading of the code.


"It is difficult to catch a black cat in a
dark room. Especially if there is no cat
there." - Confucius

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