Re: dynamic allocation vs array

From: Tan Thuan Seah (u2567446_at_anu.edu.au)
Date: 09/10/04


Date: Fri, 10 Sep 2004 21:44:19 +1000

Thanks for everyone's contribution. Actually I am currently working on a
project on sparse matrix ordering which involves quite a fair bit of graph
and sets and stuff. I am looking for an efficient way to implement the sets
and graph. As Old Wolf suggested using vectors, I came across the set in
STL. Has anyone has anyone good experiences using a combination of vectors
and set? Do they go well together?

Last bit would be to figure out a way for the graph. The book I am reading
(Computer Solution of Large Sparse Positive Definite Systems by Alan George
and Joseph W. Liu) briefly mentioned about storing the graph with 2 arrays.
But since the input matrices are going to differ in size, I need to find a
dynamic way to allocate the arrays. Vector seems pretty to be a potential
candidate. I am still open to other suggestion though. Thanks.

Thuan Seah

"Ioannis Vranos" <ivr@guesswh.at.grad.com> wrote in message
news:chrvrc$2lla$1@ulysses.noc.ntua.gr...
> Tan Thuan Seah wrote:
>
> > Hi all,
> >
> > I was told this in one of the university course I was doing.
> >
> > In C we may expect good performance for:
> > double a[N][N], c[N][N], d;
> > for (i=0; i<N; i++)
> > for(j=0; j<N; j++)
> > a[i][j] = a[i][j] + c[i][j] *d;
> >
> > But this is another matter:
> > double *a[N], *c[N], d;
> > for(i=0; i<N; i++) {a[i] = (double *) malloc(N*sizeof(double));
> > c[i] = (double *) malloc(N*sizeof(double)); }
> >
> > for(i=0; i<N; i++)
> > for(j=0; j<N; j++)
> > a[i][j] = a[i][j] + c[i][j] * d;
> >
> >
> > It seems that we would expect some performance hit if we were to use
dynamic
> > memory allocation of some sort. But it's not a standard ANSI C++ to have
> > array with the size determined during runtime. So is there any good
> > recommendation to minimize this performance hit or totally avoiding it
> > through some other method? I would expect a linked list to be even
worse.
> > Any recommendation? Thanks.
>
>
> Example code:
>
>
> #include <vector>
>
>
> int main()
> {
> using namespace std;
>
> int n=8;
>
> vector<vector<int> > someVector(n, vector<int>(n));
>
>
> someVector[3][2]=4;
>
> }
>
>
>
> If you have to, you may use a valarray. Also check this:
>
> http://www23.brinkster.com/noicys/cppfaq.htm
>
>
>
>
> --
> Ioannis Vranos
>
> http://www23.brinkster.com/noicys

------------ And now a word from our sponsor ----------------------
For a quality mail server, try SurgeMail, easy to install,
fast, efficient and reliable. Run a million users on a standard
PC running NT or Unix without running out of power, use the best!
---- See http://netwinsite.com/sponsor/sponsor_surgemail.htm ----



Relevant Pages

  • Re: Help with passing arrays to a Perl subroutine
    ... I have module from CPAN named Graph. ... this to pass in two arrays; x-axis and y-axis into my Graph subroutine ... as separate parameters. ...
    (perl.beginners)
  • Re: Help with passing arrays to a Perl subroutine
    ... this to pass in two arrays; x-axis and y-axis into my Graph subroutine ... as separate parameters. ... The '\' character returns a scalar reference ...
    (perl.beginners)
  • Re: Help! Plotting to scatter graph
    ... graph has to be short that 255 characters (run up against this one ... If your sets of values produces arrays as strings in the series formula with ...
    (microsoft.public.excel.programming)
  • Re: Area Charts With Negative Numbers
    ... to shift all the benchmark points to be non-negative and then plot ... > I'm curious if anyone has had success trying to design an area chart ... > 3) Currently I'm generating line plots for all the arrays. ... Then I put the shifted graph below another graph ...
    (microsoft.public.excel)
  • Displaying a section of a graph.
    ... I am getting data from a device on a USB bus and building time and data ... display on a XY graph. ... I tried selecting a subset of the data and time arrays with the zero indices ...
    (comp.lang.labview)