Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!lll-winken!gandalf!jac From: jac@gandalf..llnl.gov (James Crotinger) Newsgroups: comp.lang.c++ Subject: Re: parameter[][] Message-ID: <65983@lll-winken.LLNL.GOV> Date: 6 Aug 90 22:09:55 GMT References: <1545@m1.cs.man.ac.uk> <26B9BF5A.7291@orion.oac.uci.edu> <37961@ucbvax.BERKELEY.EDU> Sender: usenet@lll-winken.LLNL.GOV Organization: Lawrence Livermore National Laboratory Lines: 29 In article <37961@ucbvax.BERKELEY.EDU> jbuck@galileo.berkeley.edu (Joe Buck) writes: > > >double **mat_alloc (int nrows, int ncols) { > double **t = new double* [nrows]; > for (int i = 0; i < ncols; i++) > t[i] = new double [ncols]; >} > There are at least a couple of problems with this approach. The first is that, as written, the inter-row spacing is not constant. This may hurt your performance on some architectures when you try to do a loop over the first index. (This is particularly true of vectorizing architectures but can also give a performance hit on systems with interleaved memory access). In fact optimization in general is greatly hindered by the use of a double ** to represent a simple square or rectanglar array since the optimizer no longer has any way of knowing that it is, indeed, dealing with such a simple layout of the data. >Joe Buck >jbuck@galileo.berkeley.edu {uunet,ucbvax}!galileo.berkeley.edu!jbuck -- ========================================================================= James A. Crotinger Lawrence Livermore National Laboratory // jac@gandalf.llnl.gov P.O. Box 808; L-630 \\ // (415) 422-0259 Livermore CA 94550 \\/