home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 21239 < prev    next >
Encoding:
Internet Message Format  |  1993-01-11  |  1.1 KB

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