home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!stanford.edu!kronos.arc.nasa.gov!joshr
- From: joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91)
- Subject: Re: C array question
- Message-ID: <1993Jan12.204011.26034@kronos.arc.nasa.gov>
- Sender: usenet@kronos.arc.nasa.gov (Will Edgington, wedgingt@ptolemy.arc.nasa.gov)
- Nntp-Posting-Host: mcc2.arc.nasa.gov
- Organization: NASA/ARC Information Sciences Division
- References: <C0prG1.AsC@plato.ds.boeing.com>
- Distribution: usa
- Date: Tue, 12 Jan 1993 20:40:11 GMT
- Lines: 49
-
- In article <C0prG1.AsC@plato.ds.boeing.com> housen@plato.ds.boeing.com (Kevin housen/.na) writes:
- >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?
-
-
- IF you need to use NewPtr or NewHandle later in the code (probably do), then
- use NewPtr. If you are justin writing a small program and can
- avoid NewPtr/Handle(), then go ahead and use mallc() -- I think it will be
- faster. Malloc 'just' calls newPtr, but deals with the mem for you. If
- you ask for a small block, it allocates 15K, returns a block to you, and
- keeps track of whats left. This is all documented in the THINKC
- manuals, and may change.
-
- If you use NewHandle, you will have to lock them and only deal with
- thier de-referenced ptrs. This is no gain.
-
-
- >
- >2. Can this be generalized to a 3D array?
-
- Yes.
- >
- >BTW, I am using THINK C 5.x
- >
- >Thanks heaps -
- >
- >Kevin Housen
- >housen@plato.ds.boeing.com
-
-
- --
- ----------------------------------
- #include <std/disclaimer.h> Josh Rabinowitz, Mac TCL programmer
- joshr@kronos.arc.nasa.gov
- "Me lost my cookie at the disco." -- Cookie Monster
-