Re: C++ is slow
From: Aggro (spammerdream_at_yahoo.com)
Date: 03/05/04
- Next message: Andrey Tarasevich: "Re: [OT] C++ is slow"
- Previous message: Leor Zolman: "Re: C++ is slow"
- In reply to: Charles Herman: "C++ is slow"
- Next in thread: Andrey Tarasevich: "Re: [OT] C++ is slow"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 05 Mar 2004 22:15:57 GMT
Charles Herman wrote:
> I have the following two programs:
>
> PROG I
> void main()
int main()
> {
> int *v = new int[NUM];
> for (int i = 0; i < NUM; ++i)
> v[i] = i;
Did you forget something? delete [] v; perhaps? We don't want to cause
memory leaks, do we?
You will also want to put return 0; at the end of main, because VC 6.0
has a bug and it will complain about int main() if you don't use that. (
It is not required by the standard, but it doesn't matter if you use it.
I personally think that it is even better to use it. )
return 0;
> }
>
> PROG II
> ~rvector() { delete [] vals; }
Note that here you are using delete, unlike you did with the first
program. This might be causing some of the time difference.
> int& operator[] (size_t idx ) { return vals[idx]; }
> };
>
> void main()
int main()
> {
> rvector v(NUM);
> for (i = 0; i < NUM; ++i)
> v[i] = i;
return 0;
> }
>
> I left out some non-germane lines, eg, defining NUM and including header
> files.
Don't do that they might contain some valuable information.
- Next message: Andrey Tarasevich: "Re: [OT] C++ is slow"
- Previous message: Leor Zolman: "Re: C++ is slow"
- In reply to: Charles Herman: "C++ is slow"
- Next in thread: Andrey Tarasevich: "Re: [OT] C++ is slow"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|