STL Benefits and Pitfalls

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply

Using STL, I suffered from the following

Poll ended at Fri Jan 16, 2004 9:20 am

My program had a poor timing
3
75%
I received a run time error
0
No votes
I had some other problem
1
25%
 
Total votes: 4

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

STL Benefits and Pitfalls

Post by shamim »

The use of STL has dramatically changed the way code in C++.
Unfortunately, we are receiving posts that reflect some pitfalls of STL.

I request everyone to share their bad experiences they had, in solving a problem using STL so that we all can be aware of it.

Although, I did not yet suffer, but I got poor timing in solving a problem, and i am sure it is due to using STL, because an alternate solution without STL, solved at a much less time.
Viktoras Jucikas
New poster
Posts: 22
Joined: Sun Oct 20, 2002 6:41 pm
Location: Lithuania
Contact:

Post by Viktoras Jucikas »

Technically, you should not get order of magnitude worse timing if using STL. There is nothing bad with STL, it just might be that you are not using it optimally (and there are millions of ways to abuse STL - but that's your problem, not STL).
Per
A great helper
Posts: 429
Joined: Fri Nov 29, 2002 11:27 pm
Location: Sweden

Post by Per »

Where is the alternative "I've had no problems with STL"? :)

There are at least two necessary conditions for STL code to be roughly as fast as (well written) "normal" code:
# The STL code is also well written.
# The STL code is compiled with some optimisation, so that methods like the []-operator for vector and many other get inlined. Sadly, this is often not the case in programming contest environments.

But as Viktoras said, you'll still only get a constant factor worse by using STL (as long as you're using it correctly).

And of course, just using cin/cout (not STL, but still a related issue) is extremely slow compared to scanf/printf, since by default, all iostream operations get synchronised with stdio. (Though it is possible to disable this synchronisation.)
Moni
Experienced poster
Posts: 202
Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:

Post by Moni »

"I had some other problem"

That's I am not well user of it! :(
And as said earlier... it's my problem, not STL... :-?

Actually they are very good stuff.....done lots of advaced things with it :)

And you should practice them with GNU C++ compiler
By downloading from sgi..........that will reduce your RTEs.
ImageWe are all in a circular way, no advances, only moving and moving!
Post Reply

Return to “C++”