public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/44066]  New: excessive memory usage when compiling array initializers.
@ 2010-05-10 17:44 john at puckerupgames dot com
  2010-05-10 22:07 ` [Bug c++/44066] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: john at puckerupgames dot com @ 2010-05-10 17:44 UTC (permalink / raw)
  To: gcc-bugs

Description:

Compiling an array with an initializer list takes memory roughly 140 times the
size of the array. For example, and array of unsigned char with 1M entries
(i.e., sizeof is 1MB), takes 140 MB to compile. An array of 5MB requires over
600MB of memory to compile. Below are some rough measurements based on the
code,

 const unsigned char arr[] = {0,0,0, /*...NUM zeros here*/ };

Array_Size  /  GCC_Memory
1M          /  149M
2M          /  289M
3M          /  510M
4M          /  566M
5M          /  623M

At the above rate, GCC could require over 4GB of memory to compile a 20MB
array. In general, GCC will exhaust system memory when compiling an array of
size (Total_System_Memory/140).

How-To-Repeat:

/* This code takes roughly (140*NUM) bytes of memory to compile.  */
const unsigned char arr[] = {0,0, /*... NUM more values here*/};

The code above compiled a "C" suffers the same problem, but GCC's memory usage
is slightly lower compared to C++, at 100 times the size of the array.

Fix:

There is a workaround, but it is undesirable. Instead of an array, use a string
literal. A string literal does not appear to have this memory usage or
scalability defect. Example:

/* BAD: */
const unsigned char arr[]={0xAB,0xCD,0xEF,...};

/* WORKAROUND: */
const unsigned char *arr=(unsigned char*)"\xAB\xCD\xEF...";


Keywords: memory-hog


-- 
           Summary: excessive memory usage when compiling array
                    initializers.
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: john at puckerupgames dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/44066] excessive memory usage when compiling array initializers.
  2010-05-10 17:44 [Bug c++/44066] New: excessive memory usage when compiling array initializers john at puckerupgames dot com
@ 2010-05-10 22:07 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-05-10 22:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-05-10 22:06 -------


*** This bug has been marked as a duplicate of 14179 ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-05-10 22:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-10 17:44 [Bug c++/44066] New: excessive memory usage when compiling array initializers john at puckerupgames dot com
2010-05-10 22:07 ` [Bug c++/44066] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).