Path: utzoo!mnetor!uunet!husc6!cmcl2!nrl-cmf!ames!amdahl!apple!dan
From: dan@Apple.COM (Dan Allen)
Newsgroups: comp.sys.mac.programmer
Subject: Re: Goin' Crazy on a Mac, or, How I Love MPW "GlobalData"
Message-ID: <9395@apple.Apple.Com>
Date: 8 May 88 23:17:31 GMT
References: <8816@eleazar.Dartmouth.EDU> <7327@drutx.ATT.COM> <23952@ucbvax.BERKELEY.EDU>
Reply-To: dan@apple.UUCP (Dan Allen)
Organization: Apple Computer Inc, Cupertino, CA
Lines: 43

David Oster's advice is sound and in fact is what Apple has done for
versions of Yacc and Lex that are used internally.  They are built with
the standard MPW C 2.0 and seem to work fine in building things like the
CFront C++ preprocessor.

DISCLIAMER:  NO, these Apple internal versions of Lex and Yacc are NOT
available for the public.  YES, I wish they were.  Lean on your favorite
product marketing people and tell them you'd like to be able to buy Lex
and Yacc and Awk for MPW and maybe they'd figure out a way to sell it.
The reason that they are not available is simple: it is a legal issue.
The lawyers are going to ruin this industry, I'll tell you, and here
again we see a licensing problem rather than an engineering problem.
Something to do with Unix and AT&T, if I recall right.

GOOD NEWS:  There is another way around global data problems with big
arrays other than saving the arrays as locked resources.  (By the way,
you can create those arrays with Rez code that is almost identical to
the C code you would have written anyway, and it works very nicely.)
If you are running into lots of large arrays because you are doing
numerical analysis stuff (finite element analysis, Runge-Kutta
integration of sets of PDQs, etc.), then the latest version of
"Numerical Recipes in C: The Art of Scientific Computing" by Press,
Flannery, Teukolsky, and Vetterling (Cambridge Press) has a great
solution to the conformant array problem which ends up putting all
arrays on the heap using malloc.  Not only does the solution fix the
global data problem, but it also fixes the conformant array problem, all
in about two lines of code.  The crux of the solution is:

	double **array;

	array = SpecialRoutine(10,10);

Where the SpecialRoutine allocates pointers to each row of the array.
It takes up a little extra overhead in terms of memory (4 bytes per row
of the matrix), but speeds up array indexing as well as solves the
conformant array problem.

Great stuff!!!

Dan Allen
Software Explorer
Apple Computer
#include