Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!rutgers!ucsd!swrinde!gem.mps.ohio-state.edu!uakari.primate.wisc.edu!xanth!mcnc!ncsuvx!ecemwl!jnh From: jnh@ecemwl.ncsu.edu (Joseph N. Hall) Newsgroups: comp.lang.c Subject: Re: A pointer to a 3-D array, or an array of ptrs to 2-D arrays? Message-ID: <4544@ncsuvx.ncsu.edu> Date: 15 Nov 89 15:52:59 GMT References: <2765@levels.sait.edu.au> <20773@mimsy.umd.edu> Sender: news@ncsuvx.ncsu.edu Reply-To: jnh@ecemwl.UUCP (Joseph N. Hall) Organization: North Carolina State University Lines: 35 As an aside, I've found it useful to dynamically allocate matrices like this (hastily paraphrased, it might have a typo or two in it): double **NewDoublem(int isize, int jsize) { int i; double **doublem, *doublev; doublem = (double **) malloc(sizeof(double *) * isize); doublev = (double *) malloc(sizeof(double) * isize * jsize); for (i = 0; i < isize; i++) { doublem[i] = doublev + i * jsize; } return doublem; } This has the advantage over the more frequently-seen approach (allocate a separate vector for each row) that you can free such a "matrix" without knowing its size: free((void *) *doublem); free((void *) doublem); ...and, of course, you make fewer calls to malloc. Hope this is a useful and not tiresomely obvious suggestion for some of you. v v sssss|| joseph hall || 4116 Brewster Drive v v s s || jnh@ecemwl.ncsu.edu (Internet) || Raleigh, NC 27606 v sss || SP Software/CAD Tool Developer, Mac Hacker and Keyboardist -----------|| Disclaimer: NCSU may not share my views, but is welcome to.