Re: dynamic allocation vs array
From: Tan Thuan Seah (u2567446_at_anu.edu.au)
Date: 09/10/04
- Next message: John Harrison: "Re: How to assign values to a UINT8 variable?"
- Previous message: Jonathan Mcdougall: "Re: run-time vs compile-time"
- In reply to: Ioannis Vranos: "Re: dynamic allocation vs array"
- Next in thread: Old Wolf: "Re: dynamic allocation vs array"
- Reply: Old Wolf: "Re: dynamic allocation vs array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 ----
- Next message: John Harrison: "Re: How to assign values to a UINT8 variable?"
- Previous message: Jonathan Mcdougall: "Re: run-time vs compile-time"
- In reply to: Ioannis Vranos: "Re: dynamic allocation vs array"
- Next in thread: Old Wolf: "Re: dynamic allocation vs array"
- Reply: Old Wolf: "Re: dynamic allocation vs array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|