Linked by anonymous on Tue 29th Mar 2011 16:05 UTC
General Development The C++ programming language is about to be updated, as the ISO steering committee for the language has approved the final draft specifying its next version. The ISO/IEC Information Technology Task Force will review the steering committee's Final Draft International Standard will review and, barring any complications, publish the draft later this year. It will be known as C++ 2011.
Thread beginning with comment 468358
To view parent comment, click here.
To read all comments associated with this story, please click here.
MORB
Member since:
2005-07-06

Done.

Here is the first test as I compiled it, on a 32 bits kubuntu linux using gcc 4.4:

#include <iostream>
#include <list>

struct struct01{ int n1; int n2; };

int main( int a, char** b )
{
std::list< struct01 > list01 { {1,2}, {2,3}, {2,3}, {2,3} };

for( auto it = list01.begin(); it != list01.end(); ++it )
std::cout << "derp\n";

return 0;
}


I've initialized the list with stuff and printed out something in the loop to make sure it's not optimized away for having no side effect. This gives additional overhead but still a far cry from what you claim, so I don't care.

Compiled with gcc 4.4.1 in i386 code, with optimization:
g++ derp.cpp -o derp -O3 -std=c++0x

The binary weights a whopping 7816 bytes. After striping (with strip -s), it's 5608 bytes.

And now for the second test:

#include <iostream>
#include <list>

struct struct01 { int n1; int n2; };
struct struct02 { int n1; int n2; };
struct struct03 { int n1; int n2; };
struct struct04 { int n1; int n2; };
struct struct05 { int n1; int n2; };
struct struct06 { int n1; int n2; };
struct struct07 { int n1; int n2; };
struct struct08 { int n1; int n2; };
struct struct09 { int n1; int n2; };
struct struct10 { int n1; int n2; };

int main( int a, char** b )
{
std::list< struct01 > list01 { {1,2}, {2,3}, {2,3}, {2,3} };
std::list< struct02 > list02 { {1,2}, {2,3}, {2,3}, {2,3} };
std::list< struct03 > list03 { {1,2}, {2,3}, {2,3}, {2,3} };
std::list< struct04 > list04 { {1,2}, {2,3}, {2,3}, {2,3} };
std::list< struct05 > list05 { {1,2}, {2,3}, {2,3}, {2,3} };
std::list< struct06 > list06 { {1,2}, {2,3}, {2,3}, {2,3} };
std::list< struct07 > list07 { {1,2}, {2,3}, {2,3}, {2,3} };
std::list< struct08 > list08 { {1,2}, {2,3}, {2,3}, {2,3} };
std::list< struct09 > list09 { {1,2}, {2,3}, {2,3}, {2,3} };
std::list< struct10 > list10 { {1,2}, {2,3}, {2,3}, {2,3} };

for( auto it = list01.begin(); it != list01.end(); ++it )
std::cout << "derp\n";
for( auto it = list02.begin(); it != list02.end(); ++it )
std::cout << "derp\n";
for( auto it = list03.begin(); it != list03.end(); ++it )
std::cout << "derp\n";
for( auto it = list04.begin(); it != list04.end(); ++it )
std::cout << "derp\n";
for( auto it = list05.begin(); it != list05.end(); ++it )
std::cout << "derp\n";
for( auto it = list06.begin(); it != list06.end(); ++it )
std::cout << "derp\n";
for( auto it = list07.begin(); it != list07.end(); ++it )
std::cout << "derp\n";
for( auto it = list08.begin(); it != list08.end(); ++it )
std::cout << "derp\n";
for( auto it = list09.begin(); it != list09.end(); ++it )
std::cout << "derp\n";
for( auto it = list10.begin(); it != list10.end(); ++it )
std::cout << "derp\n";

return 0;
}


It compiles to a vastly bloated binary of 11913 bytes. After striping, it's 9704 bytes.

Reply Parent Score: 4

rom508 Member since:
2007-04-20

Sorry I made a mistake, it was some time ago when I did the tests and I don't have the sources. It wasn't 200K I got confused, I think the size difference was something like 2K.

Your test program is a bit simplistic, you need to call functions to insert items into list, then traverse the list, deleting every item. This is more or less what real code does.

So 2K is not a huge size, but it's still much more than similar implementation in C. In a large program bloat from STL can add up pretty quickly.

Reply Parent Score: 1

MORB Member since:
2005-07-06

Sorry I made a mistake, it was some time ago when I did the tests and I don't have the sources. It wasn't 200K I got confused, I think the size difference was something like 2K.

Your test program is a bit simplistic, you need to call functions to insert items into list, then traverse the list, deleting every item. This is more or less what real code does.

I implemented the test program that you suggested, and mainly with the goal to dispel that bogus 200k claim. Making a more complicated test program would only allow a meaningful comparison if compared to a program doing the same thing in pure C.

So 2K is not a huge size, but it's still much more than similar implementation in C.

If you keep comparing a concrete C++ example with some undefined "similar implementation in C", then yes, the concrete implementation is going to lose the comparison to the imaginary implementation every time.

There are many parameters. Would the C version be implemented as inline code or separate functions? Would it use a custom allocator or not? Are we talking about a thread-safe implementation or not?

In a large program bloat from STL can add up pretty quickly.

You have yet to make a compelling case that it is "bloat" and not "stuff one have to implement themselves if not using the STL". And "pretty quickly" compared to what? How do you define "pretty quickly" in this context anyway?

Reply Parent Score: 3

alexeiz Member since:
2011-03-30

The size of the binary increased because you wrote more code (ten lists objects initialized instead of one, ten lists traversed), not because you used list with 10 different structs. If you do 'objdump' on the binary I think you'll find only a single instantiation of the list.

Reply Parent Score: 1

MORB Member since:
2005-07-06

I didn't expect the number of different types to be a factor but I was humoring mr "OMG STL adds 200k of code for a linked list".

Reply Parent Score: 2