home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 21311 < prev    next >
Encoding:
Text File  |  1993-01-12  |  2.1 KB  |  63 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!stanford.edu!kronos.arc.nasa.gov!joshr
  3. From: joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91)
  4. Subject: Re: C array question
  5. Message-ID: <1993Jan12.204011.26034@kronos.arc.nasa.gov>
  6. Sender: usenet@kronos.arc.nasa.gov (Will Edgington, wedgingt@ptolemy.arc.nasa.gov)
  7. Nntp-Posting-Host: mcc2.arc.nasa.gov
  8. Organization: NASA/ARC Information Sciences Division
  9. References: <C0prG1.AsC@plato.ds.boeing.com>
  10. Distribution: usa
  11. Date: Tue, 12 Jan 1993 20:40:11 GMT
  12. Lines: 49
  13.  
  14. In article <C0prG1.AsC@plato.ds.boeing.com> housen@plato.ds.boeing.com (Kevin housen/.na) writes:
  15. >I am making a jump from Pascal to C and have a simple question
  16. >regarding creation of a 2D array at runtime.  I want to create
  17. >an array of floats r rows by c columns.  A (non-Mac) friend
  18. >suggests
  19. >
  20. >        float **m        /* this will be the 2D array */
  21. >        int r, c, count
  22. >
  23. >        m = (float **) malloc (r*sizeof(float *));
  24. >        for (count=0, count < r, count++)
  25. >            m[count] = (float *) malloc (c * sizeof(float) );
  26. >
  27. >1.  If, instead of malloc, I want to use the Mac memory manager
  28. >   routines, does it matter if I use NewPtr or NewHandle (assuming
  29. >   I lock handles at the appropriate times)?  Does malloc just
  30. >   call NewPtr?
  31.  
  32.  
  33. IF you need to use NewPtr or NewHandle later in the code (probably do), then
  34. use NewPtr.  If you are justin writing a small program and can
  35. avoid NewPtr/Handle(), then go ahead and use mallc() -- I think it will be
  36. faster.  Malloc 'just' calls newPtr, but deals with the mem for you.  If
  37. you ask for a small block, it allocates 15K, returns a block to you, and
  38. keeps track of whats left.  This is all documented in the THINKC
  39. manuals, and may change.
  40.  
  41. If you use NewHandle, you will have to lock them and only deal with 
  42. thier de-referenced ptrs.  This is no gain.
  43.  
  44.  
  45. >
  46. >2.  Can this be generalized to a 3D array?
  47.  
  48. Yes.
  49. >
  50. >BTW, I am using THINK C 5.x
  51. >
  52. >Thanks heaps -
  53. >
  54. >Kevin Housen
  55. >housen@plato.ds.boeing.com
  56.  
  57.  
  58. -- 
  59. ----------------------------------
  60. #include <std/disclaimer.h>     Josh Rabinowitz, Mac TCL programmer
  61. joshr@kronos.arc.nasa.gov
  62. "Me lost my cookie at the disco." -- Cookie Monster
  63.