Welcome, Unregistered.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Reply
Old 14-Aug-2012, 19:40   #1
imaxx
Junior Member
 
Join Date: Mar 2012
Location: cracks
Posts: 53
Default Not Using STL is good because...

Today I did run in a funny issue in my work (let's say an engineering team in a cool company in a cool project).

I won't enter details, but it all ended up to this, said by a 50yr SW engineer:

Quote:
For portability issues you should never use STL - you should write your own code. I trust more my code (than STL one)

...just wanted to share with you all, it would have made my day if it weren't happening to me...
imaxx is offline   Reply With Quote
Old 14-Aug-2012, 22:51   #2
Davros
Darlek ******
 
Join Date: Jun 2004
Posts: 9,486
Default

Quote:
Originally Posted by imaxx View Post
Today I did run in a funny issue in my work (let's say an engineering team in a cool company in a cool project).
So we can rule microsoft out
__________________
Guardian of the Most holy Two Terabytes of Gaming Goodness™
Davros is offline   Reply With Quote
Old 14-Aug-2012, 23:02   #3
PixResearch
Junior Member
 
Join Date: May 2010
Location: London
Posts: 68
Default

Warning treated as error: STL has been deprecated.
Please use STL_s
PixResearch is offline   Reply With Quote
Old 14-Aug-2012, 23:40   #4
Humus
Crazy coder
 
Join Date: Feb 2002
Location: Stockholm, Sweden
Posts: 3,216
Send a message via ICQ to Humus Send a message via MSN to Humus
Default

For the record, STL has portability issues. Some stuff behaves different on different platforms. Not necessarily in a way that is out of spec, but implementations vary and certainly performance characteristics. A typical example is calling std::vector.clear(). Some implementations will free the memory, some will merely set the size to zero retaining all allocated memory. To really make sure it frees the memory you have to write some really ugly code, e.g.: http://stackoverflow.com/questions/3...or-a-stdvector

If you have your own code, you have full control. You can free or retain memory as you please. You have a choice in exact algorithms and memory allocation schemes. Depending on the needs of your cool project in the cool company, this may matter quite a great deal. Certainly for game development these factors typically outweighs any perceived benefit of STL. For us, the use of STL is generally discouraged within the company. Of course, there are bits and pieces in there that makes sense for us too, like std::sort(), but using for instance an std::vector is rarely the right thing to do. Our own Array class on the other hand will behave exactly as we implemented it on all platforms.
__________________
[ Visit my site ]
I speak for myself and only myself.
Humus is offline   Reply With Quote
Old 15-Aug-2012, 00:38   #5
McHuj
Member
 
Join Date: Jul 2005
Location: Austin, Tx
Posts: 408
Default

Quote:
Originally Posted by imaxx View Post
Today I did run in a funny issue in my work (let's say an engineering team in a cool company in a cool project).

I won't enter details, but it all ended up to this, said by a 50yr SW engineer:

...just wanted to share with you all, it would have made my day if it weren't happening to me...
I agree with him.
McHuj is offline   Reply With Quote
Old 15-Aug-2012, 00:41   #6
ERP
Moderator
 
Join Date: Feb 2002
Location: Redmond, WA
Posts: 3,149
Default

We avoid it, and I know a lot of places where using STL is against the coding standards.

If you don't care about the implementation it's fine for what it is, IME the STL implementation is rarely what you actually want.
ERP is offline   Reply With Quote
Old 15-Aug-2012, 00:51   #7
imaxx
Junior Member
 
Join Date: Mar 2012
Location: cracks
Posts: 53
Default

Quote:
Originally Posted by McHuj View Post
I agree with him.
This is really interesting - can you tell me why? A good reason to use your own list/tree instead of ready-made and tested ones.

As long as you don't have issues with:
* best possible speed, to death like i.e. vgame development.
* embedded devices (where even a full clib would be a problem).

@Humus: agree, for example ANSI doesnt say anything about i.e. going before begin iterator. Yet, what makes you think your code is better tested and stabler than STL one?

Last edited by imaxx; 15-Aug-2012 at 00:56.
imaxx is offline   Reply With Quote
Old 15-Aug-2012, 02:04   #8
McHuj
Member
 
Join Date: Jul 2005
Location: Austin, Tx
Posts: 408
Default

Quote:
Originally Posted by imaxx View Post
This is really interesting - can you tell me why? A good reason to use your own list/tree instead of ready-made and tested ones.

As long as you don't have issues with:
* best possible speed, to death like i.e. vgame development.
* embedded devices (where even a full clib would be a problem).

@Humus: agree, for example ANSI doesnt say anything about i.e. going before begin iterator. Yet, what makes you think your code is better tested and stabler than STL one?
Funny you say that, because the two issues you mentioned are my issues.

The main reasons are speed in embedded applications and full control over the code/implementation. Now, I'm not coming from the video game world, but a DSP one where performance to handcounted cycles is king. But even then, some times our code needs to execute on a non native platform like x86 where realtime speed isn,t an issue, but it would would be, imo, to cumbersome to maintain two implementations of code (one STL and one not) to enable that.
McHuj is offline   Reply With Quote
Old 15-Aug-2012, 02:18   #9
3dcgi
Senior Member
 
Join Date: Feb 2002
Posts: 2,019
Default

A lot of people seem to not like STL, but Humus is the first I've casually run across that gave a specific reason. Most people just say it's too slow. That might be true for some cases and there are a lot of people here with more programming experience than I, but there are many applications that won't have a performance issue with STL and will benefit more from increased productivity.

I use STL extensively in a database application that runs on Windows and Linux and while it's possible memory isn't being handled the same way I've never noticed any functional difference in my program.
3dcgi is offline   Reply With Quote
Old 15-Aug-2012, 05:45   #10
epicstruggle
Passenger on Serenity
 
Join Date: Jul 2002
Location: Object in Space
Posts: 1,891
Default

Quote:
Originally Posted by 3dcgi View Post
A lot of people seem to not like STL, but Humus is the first I've casually run across that gave a specific reason. Most people just say it's too slow. That might be true for some cases and there are a lot of people here with more programming experience than I, but there are many applications that won't have a performance issue with STL and will benefit more from increased productivity.

I use STL extensively in a database application that runs on Windows and Linux and while it's possible memory isn't being handled the same way I've never noticed any functional difference in my program.
Don't use STL either, but that's mainly because I work in a assembly-like language where we dont have it.
__________________
"everyone is entitled to his own opinion, but not his own facts"
epicstruggle is offline   Reply With Quote
Old 15-Aug-2012, 10:10   #11
Ethatron
Member
 
Join Date: Jan 2010
Posts: 375
Default

Writing your own allocator should overwrite black-box allocator behaviours, I think.
Ethatron is offline   Reply With Quote
Old 15-Aug-2012, 12:10   #12
itsmydamnation
Member
 
Join Date: Apr 2007
Location: Australia
Posts: 644
Default

so then..... what should someone learning c++ do, everything i have touched pretty much uses STL whether its string or console in/out etc. As a hack do i just continue using STL or at what point is it worth building your own library of functions/data types etc.


cheers
itsmydamnation is offline   Reply With Quote
Old 15-Aug-2012, 12:32   #13
Rodéric
a.k.a. Ingenu
 
Join Date: Feb 2002
Location: Apsley, U.K.
Posts: 2,726
Default

I used stdint.h from C99 for types, and std::string (lazy ) + std::vector (in tools).

Ill defined spec, not playing well with serialization are two reasons to avoid STL.
(Barely readable errors don't really help either.)

A lot of programmers like short readable code, STL just doesn't fit.
__________________
So many things to do, and yet so little time to spend...
Rodéric is offline   Reply With Quote
Old 15-Aug-2012, 13:02   #14
McHuj
Member
 
Join Date: Jul 2005
Location: Austin, Tx
Posts: 408
Default

Quote:
Originally Posted by itsmydamnation View Post
so then..... what should someone learning c++ do, everything i have touched pretty much uses STL whether its string or console in/out etc. As a hack do i just continue using STL or at what point is it worth building your own library of functions/data types etc.


cheers
I think you should learn STL. It's important to know. But it's kind of a judgment call when to use STL or not that just comes with experience.
McHuj is offline   Reply With Quote
Old 15-Aug-2012, 16:16   #15
epicstruggle
Passenger on Serenity
 
Join Date: Jul 2002
Location: Object in Space
Posts: 1,891
Default

Quote:
Originally Posted by McHuj View Post
I think you should learn STL. It's important to know. But it's kind of a judgment call when to use STL or not that just comes with experience.
STL can make you lazy, I like to get my hands dirty and code most of what I could get for free with STL. Comes with risks, but you get to understand how things like memory allocation happen and where pitfalls can arise.
__________________
"everyone is entitled to his own opinion, but not his own facts"
epicstruggle is offline   Reply With Quote
Old 15-Aug-2012, 16:27   #16
Gubbi
Senior Member
 
Join Date: Feb 2002
Posts: 2,543
Default

IMO, the STL container templates has great utility. Probably not fit for hardcore performance kernels.

Cheers
__________________
I'm pink, therefore I'm spam
Gubbi is offline   Reply With Quote
Old 15-Aug-2012, 16:43   #17
AlexV
Heteroscedasticitate
 
Join Date: Mar 2005
Posts: 2,354
Default

Quote:
Originally Posted by itsmydamnation View Post
so then..... what should someone learning c++ do

cheers
Focus on learning it and on those who teach it. Then you can move on to the grey area of quirky worries. There is a reason for which most books trying to teach usable modern C++ use the STL quite a bit, and it's not because the guys writing them are evil.
__________________
Donald Knuth: Science is what we understand well enough to explain to a computer. Art is everything else we do.
AlexV is offline   Reply With Quote
Old 15-Aug-2012, 19:08   #18
Ethatron
Member
 
Join Date: Jan 2010
Posts: 375
Default

Right. And you can program rather quick complex things, which is good when you come from high level languages and don't want to be bothered to implement every quinch of a simple common data-structure. If you need to start to be worried about specific aspects of a STL implementation (performance, compliance, etc.), you have become a pro anway. So learn it, use it, and judge it by it's utility value in time.
Ethatron is offline   Reply With Quote
Old 15-Aug-2012, 20:25   #19
Humus
Crazy coder
 
Join Date: Feb 2002
Location: Stockholm, Sweden
Posts: 3,216
Send a message via ICQ to Humus Send a message via MSN to Humus
Default

Quote:
Originally Posted by Ethatron View Post
Writing your own allocator should overwrite black-box allocator behaviours, I think.
Default allocators are typically just wrappers around new and delete anyway. But even with a custom allocator, you'd still have the problem I mentioned with clear(), because an implementation that retains the memory wouldn't even call into your allocator. If you're a game developer, the std::vector clear() issue can matter because Microsoft's and Sony's implementations do this differently. I don't remember which one did what, but this was an issue we ran into at one point.

Another problem with std::vector is of course that every push to it will check capacity and potentially resize. Normally you know ahead of time how many items you will need, so for performance reasons it's better to just set capacity upfront and then fill it in. This pulls capacity checks and allocations out of the inner loop. Also reduces memory fragmentation.
__________________
[ Visit my site ]
I speak for myself and only myself.
Humus is offline   Reply With Quote
Old 15-Aug-2012, 20:38   #20
Npl
Senior Member
 
Join Date: Dec 2004
Posts: 1,746
Default

But aint this something you can easily replace at any time? I think this is STLs biggest strength, once you seen through the design choices, you can take your own vector class or template and use it everywhere.
you arent tied to specific classes.

STL is a great thing to get going, the rest is something you can solve when its necessary
Npl is offline   Reply With Quote
Old 16-Aug-2012, 02:09   #21
3dcgi
Senior Member
 
Join Date: Feb 2002
Posts: 2,019
Default

Quote:
Originally Posted by Rodéric View Post
A lot of programmers like short readable code, STL just doesn't fit.
In theory programmers like short readable code, but many don't adhere to the theory. Personally I think STL is very readable at an algorithm level. Of course it abstracts the execution details.

Quote:
Originally Posted by Humus View Post
Another problem with std::vector is of course that every push to it will check capacity and potentially resize. Normally you know ahead of time how many items you will need, so for performance reasons it's better to just set capacity upfront and then fill it in. This pulls capacity checks and allocations out of the inner loop. Also reduces memory fragmentation.
My machine learning program pushes a lot of data into a vector and I ran across this issue. So now I estimate what I'll need and preallocate large chunks of memory at a time. I didn't do extensive profiling, but it seemed to help.
3dcgi is offline   Reply With Quote
Old 16-Aug-2012, 02:10   #22
rpg.314
Senior Member
 
Join Date: Jul 2008
Location: /
Posts: 4,070
Send a message via Skype™ to rpg.314
Default

STL is one of the reasons why I use C++ over plain C. For a beginner, I'd recommend using it right away. With lambda's in C++11, STL is now 100x more usable.

Situations's like Humus' are rare enought that any beginner would not need to consider them.
__________________
The views presented here are my own and not my employer's.
Quote:
Originally Posted by Alexko View Post
So in a nutshell, model [BLANK] will have [BLANK], up to [BLANK], and even [BLANK] for a power consumption of just [BLANK]. Impressive.
rpg.314 is offline   Reply With Quote
Old 16-Aug-2012, 19:15   #23
zed
Member
 
Join Date: Dec 2005
Posts: 2,089
Default

http://www.open-std.org/jtc1/sc22/wg...007/n2271.html
__________________
stalk me on twitter
zed is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:59.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.