Re: C++ is slow
From: Julie (julie_at_aol.com)
Date: 03/06/04
- Next message: Alf P. Steinbach: "Re: C++ is slow"
- Previous message: Mike Wahler: "Re: Is std::vector contiguous?"
- In reply to: Mike Wahler: "Re: C++ is slow"
- Next in thread: Alf P. Steinbach: "Re: C++ is slow"
- Reply: Alf P. Steinbach: "Re: C++ is slow"
- Reply: Andrey Tarasevich: "Re: C++ is slow"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 05 Mar 2004 16:57:46 -0800
Mike Wahler wrote:
>
> "Charles Herman" <cherman@no.spam> wrote in message
> news:PO62c.120645$Xp.533671@attbi_s54...
> > I have the following two programs:
> >
> > PROG I
> > void main()
>
> int main()
>
> If you use anything else besides 'int' return type
> for main, you have *no* guarantees about the behavior of
> your program.
>
> > {
> > int *v = new int[NUM];
> > for (int i = 0; i < NUM; ++i)
> > v[i] = i;
>
> You have a memory leak. You need to free the memory
> you allocate.
>
> > }
> >
> > PROG II
> > class rvector
> > {
> > private:
> > int* vals;
> > size_t vsize;
> >
> > public:
> > explicit rvector( size_t vSize ) { vals = new int[vsize]; }
> > ~rvector() { delete [] vals; }
> >
> > int& operator[] (size_t idx ) { return vals[idx]; }
> > };
> >
> > void main()
>
> And again.
>
> > {
> > rvector v(NUM);
> > for (i = 0; i < NUM; ++i)
> > v[i] = i;
> > }
> >
> > I left out some non-germane lines, eg, defining NUM and including header
> > files.
>
> You should always strive to post *compilable* code if at all
> possible. Then we needn't guess at the rest, which is often
> the cause of a stated problem.
>
> >
> > I compiled and ran these programs using VC++ 6.0. The second program
> > required approx 6 times as much time to run as the first. What is
> happening
> > in program II that takes so much time?
>
> The C++ language is a set of specifications, an abstraction.
> I has no 'speed', slow or fast. Apparently you find a particular
> *implementation* of C++, (VC++6.0) "too slow".
>
> Recommended actions:
>
> Read your documentation to ensure you're using the product correctly,
> and find it's various 'modes' of operation.
>
> If VC++ is deemed unacceptable, use something else.
>
> -Mike
Crap. You answered anything but the OP's question.
void main, memory leaks, using different compilers, and diatribes about speed
in the standard don't do a thing for the OP and their perceived differences in
speed.
I think that Leor was the only one to infer as to the *real* problem here. I
didn't see the problem until he pointed it out.
Let's remember that this isn't
comp.lang.c++.lets.run.off.the.newbies.as.fast.as.possible.
- Next message: Alf P. Steinbach: "Re: C++ is slow"
- Previous message: Mike Wahler: "Re: Is std::vector contiguous?"
- In reply to: Mike Wahler: "Re: C++ is slow"
- Next in thread: Alf P. Steinbach: "Re: C++ is slow"
- Reply: Alf P. Steinbach: "Re: C++ is slow"
- Reply: Andrey Tarasevich: "Re: C++ is slow"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|