home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!seismo!news.bbn.com!micro-heart-of-gold.mit.edu!uw-beaver!fluke!plato!housen
- From: housen@plato.ds.boeing.com (Kevin housen/.na)
- Newsgroups: comp.sys.mac.programmer
- Subject: C array question
- Message-ID: <C0prG1.AsC@plato.ds.boeing.com>
- Date: 11 Jan 93 23:48:01 GMT
- Distribution: usa
- Organization: Boeing Defense & Space Group
- Lines: 25
-
- I am making a jump from Pascal to C and have a simple question
- regarding creation of a 2D array at runtime. I want to create
- an array of floats r rows by c columns. A (non-Mac) friend
- suggests
-
- float **m /* this will be the 2D array */
- int r, c, count
-
- m = (float **) malloc (r*sizeof(float *));
- for (count=0, count < r, count++)
- m[count] = (float *) malloc (c * sizeof(float) );
-
- 1. If, instead of malloc, I want to use the Mac memory manager
- routines, does it matter if I use NewPtr or NewHandle (assuming
- I lock handles at the appropriate times)? Does malloc just
- call NewPtr?
-
- 2. Can this be generalized to a 3D array?
-
- BTW, I am using THINK C 5.x
-
- Thanks heaps -
-
- Kevin Housen
- housen@plato.ds.boeing.com
-