#include <vector>

void foo(int n)
{
        std::vector<int> v;
        for (int i=0; i<n; ++i)
                v.push_back(i);
}

here the (single) variable storage allocated on the heap can be promoted
to stack allocation, where the (single) object can grow dynamically.  This
happens in even more libstdc++ code and is generally exposed after inlining
only.

Note that due to the missing realloc primitive in C++, growing is done
as new + memmove pair, so detection of this case is somewhat harder.


-- 
           Summary: Variable sized storage allocation should be promoted to
                    stack allocation
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org
 BugsThisDependsOn: 26387


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26388

Reply via email to