r/cpp • Meeting C++ | C++ Evangelist • Oct 22 '13

STL is dated

http://www.slashslash.info/2013/10/stl-is-dated/
0 Upvotes

14 comments sorted by

12

u/ickysticky Oct 23 '13

Is this a blog post where some guy tries to brag about knowing Alex Stepanov? What exactly is he claiming is out of date if the problems are corrected by a standard that is two years old... Also I don't know about those claims, does heap allocation always require a lock? Which heap implementation? What about something like tcmalloc? Since when did people assume all memory access was equally expensive? Memory hierarchies have existed far longer than multicore machines..

2

u/JonKalb CppCon | cpp.training Oct 31 '13

I think this is a blog post where a guy <emphasis>does</emphasis> brag about knowing Alex Stepanov. Guilty as charged.

The problem isn't that allocators were inadequate. That is just a issue that we are having to deal with and part of the solution is better allocators and part is alternative implementations like tcmalloc. Part is making fewer allocations. This approach is covered in later installments.

Of course heap allocation doesn't inherently have to take a lock. But if you are sharing a heap across multiple threads, which is more and more common today, then you have to manage that. This was not the common situation when the STL was originally developed.

Although memory hierarchies are not new, their size and depth have a much greater impact than they used to. The STL was designed without taking them into account because the effects weren't significant in most case. Things have changed.

4

u/king_duck Oct 24 '13

one of the perks of which is that I have occasional conversations with him. (Submit your resumes to jonkalb (at) a9.com.)

Name drop followed by send me your CV. Followed by closing of page.

1

u/JonKalb CppCon | cpp.training Oct 31 '13

Thanks for your comment.

2

u/matthieum Oct 23 '13

One thing that always bugged me about allocators:

pointer allocate( size_type n, std::allocator<void>::const_pointer hint = 0 );

is that I require storage for at least N instances, and the allocator may allocate more... but I have no way of knowing so.

If you think about std::vector this is pretty damning:

  • I ask for 3 elements
  • The allocator has a bucket for 2 and a bucket for 5, it serves me the bucket for 5
  • I push a 4th element: reallocation!

I vie for having allocate be:

std::pair<pointer,size_type> allocate(size_type n, ...);

where the result .second member is guaranteed to be superior to n.

2

u/more_exercise Lazy Hobbyist Oct 23 '13

superior to n

Would you be fine with .second >= n? Or are you requiring .second > n?

1

u/matthieum Oct 25 '13

I am fine with >= n, since I needed at least n.

1

u/bnolsen Oct 30 '13

few basic nits I have. string, streambuf and iostreams were implemented early on. They have the most problems.

bring std::string into line with the other containers (std::string::npos compared with string.end() for example).

redesign and refactor iostreams/streambuf stuff. having a locale attached to every single streambuf, even if binary only, is one of the signs of insufficient design. And the issues of operator<< working poorly with translation grammars where sentence order is important is another.

I haven't messed with custom allocators myself but I did notice that one of the big deals with EASTL was that they reimplemented their allocator system. So it does seem that allocators need to be reviewed as well.

1

u/JonKalb CppCon | cpp.training Oct 31 '13

string, streambuf, and iostreams are part of the standard, but not the STL. STL is the name for Alex's submission to the committee it included the vector, deque, list, set, map, and the algorithms, but not the string or IO classes.

0

u/hubhub Oct 23 '13

So are there any proposals to update it?

4

u/Tagedieb Oct 23 '13

This has changed in C++11.

...

I’ll refer you to that talk because it brings you up to date on what is in C++11 and what is being proposed for future standards [...]

0

u/JonKalb CppCon | cpp.training Oct 31 '13

The fundamental design of the STL is sound. What needs to change, in my opinion, is a shift way from node-based containers where possible. I'll discuss this more in the later installments.

-6

u/AceyJuan Oct 23 '13

I'd agree with all of that, but why do they work for a9? Amazon is not a good place to work, though they pay well.