Re: C++ is slow
From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 03/05/04
- Next message: Mike Wahler: "Re: (P.S.) C++ is slow"
- Previous message: Charles Herman: "C++ is slow"
- In reply to: Charles Herman: "C++ is slow"
- Next in thread: Mike Wahler: "Re: (P.S.) C++ is slow"
- Reply: Mike Wahler: "Re: (P.S.) C++ is slow"
- Reply: Julie: "Re: C++ is slow"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 05 Mar 2004 22:08:46 GMT
"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
- Next message: Mike Wahler: "Re: (P.S.) C++ is slow"
- Previous message: Charles Herman: "C++ is slow"
- In reply to: Charles Herman: "C++ is slow"
- Next in thread: Mike Wahler: "Re: (P.S.) C++ is slow"
- Reply: Mike Wahler: "Re: (P.S.) C++ is slow"
- Reply: Julie: "Re: C++ is slow"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|