Re: C++ is slow

From: Julie (julie_at_aol.com)
Date: 03/06/04


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.



Relevant Pages

  • Re: C++ is slow
    ... > void main ... If you use anything else besides 'int' return type ... > PROG II ...
    (comp.lang.cpp)
  • Memory leak problem
    ... After following the advice received in this list, I have isolated the memory leak problem I am having. ... List = initVoiceChannels(List, TempEvent); ... float generateRandomNumber(int intervalA, int intervalB, int incValues) { ... DLLIST *DLCreate(int Tag, void *Object, size_t Size) ...
    (comp.lang.c)
  • Re: C++ is slow
    ... > void main ... memory leaks, do we? ... has a bug and it will complain about int mainif you don't use that. ... > PROG II ...
    (comp.lang.cpp)
  • Re: concurrent calls to system(const char *)
    ... "int system". ... std::ostringstream st1; ... This has a rather large memory leak, in that you never free all those ... void *f ...
    (comp.os.linux.development.system)
  • Re: My solution to allocating memory
    ... int main{ ... void *p; ... /* no memory leak, the pointer is held ...
    (comp.lang.c)