This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/48481] New: C++ overloading memory hog


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

           Summary: C++ overloading memory hog
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: memory-hog
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jakub@gcc.gnu.org
                CC: jason@gcc.gnu.org


#define A(n) \
struct S##n { int i; }; \
S##n v##n;\
extern int foo (S##n, S##n);\
extern void bar (S##n);
#define B(n) A(n##0) A(n##1) A(n##2) A(n##3) A(n##4) A(n##5) A(n##6) A(n##7)
A(n##8) A(n##9)
#define C(n) B(n##0) B(n##1) B(n##2) B(n##3) B(n##4) B(n##5) B(n##6) B(n##7)
B(n##8) B(n##9)
#define D(n) C(n##0) C(n##1) C(n##2) C(n##3) C(n##4) C(n##5) C(n##6) C(n##7)
C(n##8) C(n##9)
#ifndef N
#define N 10000
#endif
#if N == 1000
#define E(n) D(n##0)
#elif N == 2000
#define E(n) D(n##0) D(n##1)
#elif N == 3000
#define E(n) D(n##0) D(n##1) D(n##2)
#else
#define E(n) D(n##0) D(n##1) D(n##2) D(n##3) D(n##4) D(n##5) D(n##6) D(n##7)
D(n##8) D(n##9)
#endif
E(0)

void
foo ()
{
#undef A
#define A(n) if (foo (v##n, v##n)) bar (v##n);
  E(0)
}

testcase eats huge amounts of memory.  With -DN=1000 -O0 it compiles quickly,
using 432768 kB of memory (852MB in top), with -DN=2000 -O0 it already uses
1672544 kB (3.5GB in top).  With -DN=3000 it took around 8GB in top.

In --enable-gather-detailed-mem-stats -fmem-report, for N=1000 I see:
cp/tree.c:1447 (ovl_cons)                          64032000:15.1%          0:
0.0%     256032: 1.8%          0: 0.0%    2009001
c-family/c-common.c:9556 (make_tree_vector)       159840120:37.8%          0:
0.0%          0: 0.0%          0: 0.0%    3996003
cp/search.c:1135 (build_baselink)                 191952000:45.4%          0:
0.0%          0: 0.0%          0: 0.0%    3999000
Total                                             422660566          8986384   
     14294815          2724053         10281399
source location                                     Garbage            Freed   
         Leak         Overhead            Times
and for N=2000:
cp/tree.c:1447 (ovl_cons)                         256064000:15.3%          0:
0.0%     512032: 1.9%          0: 0.0%    8018001
c-family/c-common.c:9556 (make_tree_vector)       639680120:38.1%          0:
0.0%          0: 0.0%          0: 0.0%   15992003
cp/search.c:1135 (build_baselink)                 767904000:45.8%          0:
0.0%          0: 0.0%          0: 0.0%   15998000
Total                                            1677099246         12464328   
     27061439          3876781         40545425
source location                                     Garbage            Freed   
         Leak         Overhead            Times


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]