Strange Growth of Executables

M

Mike Copeland

I've encountered a strange (to me) situation as I migrate a lot of C-
based code to C++ code and structures. (Using VS10 Express.)
Specifically, as I convert large data arrays (both structures and POD
arrays) to vectors, the executable files grow and grow (!). Once I
change one array to a vector (and accept the STL runtime expansion), I
would expect that changing more data in the same program would, at
worst, keep the executable size static. At best, I had hoped the
programs would shrink...because allocating large data areas (e.g. int
[60000] -> vector{int>) would produce less code and smaller executables.
In fact, the opposite of my expectations occurs: the more I change,
the larger the programs grow (no other changes or functionality mods).
This really surprises me, as I had thought STL code would be smaller
and more efficient... 8<{{
Any thoughts on this? TIA
 
R

red floyd

I've encountered a strange (to me) situation as I migrate a lot of C-
based code to C++ code and structures. (Using VS10 Express.)
Specifically, as I convert large data arrays (both structures and POD
arrays) to vectors, the executable files grow and grow (!). Once I
change one array to a vector (and accept the STL runtime expansion), I
would expect that changing more data in the same program would, at
worst, keep the executable size static. At best, I had hoped the
programs would shrink...because allocating large data areas (e.g. int
[60000] -> vector{int>) would produce less code and smaller executables.
In fact, the opposite of my expectations occurs: the more I change,
the larger the programs grow (no other changes or functionality mods).
This really surprises me, as I had thought STL code would be smaller
and more efficient... 8<{{
Any thoughts on this? TIA

Are you sure that you're not seeing debug/symbol info growing? Have
you done anything to measure code/data size?

The size of an EXE is a matter of many thing, of which code/data are
a small part.
 
Ö

Öö Tiib

I've encountered a strange (to me) situation as I migrate a lot of C-
based code to C++ code and structures. (Using VS10 Express.)
Specifically, as I convert large data arrays (both structures and POD
arrays) to vectors, the executable files grow and grow (!). Once I
change one array to a vector (and accept the STL runtime expansion), I
would expect that changing more data in the same program would, at
worst, keep the executable size static. At best, I had hoped the
programs would shrink...because allocating large data areas (e.g. int
[60000] -> vector{int>) would produce less code and smaller executables.
In fact, the opposite of my expectations occurs: the more I change,
the larger the programs grow (no other changes or functionality mods).
This really surprises me, as I had thought STL code would be smaller
and more efficient... 8<{{
Any thoughts on this? TIA

Thoughts are such:

1) VS2010 contains experimental compiler that compiles something that is not
C++03 nor C++11.

2) 'std::vector' is dynamic array. Dynamic array you get with
'int* array = malloc(60000*sizeof(int))' in C.

3) 'std::array' is static array and 'int[60000]' is 'std::array<int,60000>'

4) When code defines 'int massive[60000] = {0};' then that does not mean that the
executable will contain 240000 '\0' bytes somewhere as result.

5) You likely measure debug builds.

6) STL contains no magic. Usage of raw static array in C produces about as
compact code as it can get. STL containers are usually safer and often as compact.

7) Mechanically translating by hand from one language to other usually results with
defects and inefficiency.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top