This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
polymorphism - virtual memory exhausted
- To: gcc-bugs at gcc dot gnu dot org
- Subject: polymorphism - virtual memory exhausted
- From: Issac Alphonso <alphonso at isip dot msstate dot edu>
- Date: Wed, 22 Nov 2000 15:13:47 -0600 (CST)
- Reply-to: alphonso at isip dot msstate dot edu
Description:
------------
I have encountered a nasty problem when compiling a List class that I am
trying to write. The List class uses a virtual pointer that can be
initialized to either a single or a double linked list via polymorphism.
When I declare multiple instances of the List class in a function and
perform several operations on it the virtual memory used in compiling
the function keeps on increasing until the compile job dies.
For some reason as the number of List class instances and operations
on those List class instances grows in the function so does the
memory needed for the compile job. Eventually the compile job dies
saying that the "virtual memory has been exhausted."
Also, the problems with the compile job dying only occurs when I
optimize the code using the -O2 flag (using gcc version 2.95.2).
I would appreciate any pointers especially if someone has
encountered a similar problem like this before. Thanks.
GCC version:
-----------
gcc version 2.95.2 19991024 (release)
Systems info:
-------------
i386-pc-solaris2.7
sparc-sun-solaris2.6
i386-pc-redhat-linux6.2
Command line:
-------------
gcc -o ListDiagnose_diag.o -I/isip/d108/alphonso/tools/include -Wall -ftemplate-depth-50 -DTEMPLATE_DIAGNOSE -include /isip/d108/alphonso/tools/class/dstr/List/ListDiagnose.h -DDIAG_CLASS_NAME=ListDiagnose<Char> -O2 -c diagnose_class.cc
Compiler output:
----------------
/home/alphonso/tools/class/dstr/List/ListDiagnose.h: In function `static boolean ListDiagnose<Char>::diagnose(Integral::DEBUG)':
diagnose_class.cc:48: instantiated from here
/home/alphonso/tools/class/dstr/List/ListDiagnose.h:3753: virtual memory exhausted
make[1]: *** [ListDiagnose_diag.o] Error 1
/isip/d109/hamaker/gcc_2_95_1/bin/gcc -I/home/alphonso/tools/include -Wall -ftemplate-depth-50 -DTEMPLATE_DIAGNOSE -include /home/alphonso/tools/class/dstr/List/ListDiagnose.h -DDIAG_CLASS_NAME=ListDiagnose<Char> -O2 -c diag_param_00.cc
make[1]: Target `install' not remade because of errors.
make[1]: Leaving directory `/home/alphonso/tools/util/devel/diagnose_class'
make: *** [ListDiagnose.exe] Error 2
Sample Code:
------------
enum LIST_TYPE { SINGLE = 0, DOUBLE, DEF_LIST_TYPE = DOUBLE };
// virtual class interface
template<class T>
class ListBase {
virtual boolean add() = 0;
virtual boolean remove(T* obj) = 0;
...
...
}
template<class T>
class List {
// virtual pointer
ListBase<T>* virtual_lst_d;
// constructor
List (LIST_TYPE arg = DEF_LIST_TYPE) {
if (arg == SINGLE) {
virtual_lst_d = new SingleLinkedList<T>();
}
else {
virtual_lst_d = new DoubleLinkedList<T>();
}
}
// call through methods for add
boolean add() {
virtual_lst_d->add();
}
// call through methods for remove
boolean remove(T* obj) {
virtual_lst_d->remove(obj);
}
...
...
}
template<class T>
class SingleLinkedList : public ListBase<T> {
boolean add();
boolean remove(T* obj);
...
...
}
template<class T>
class DoubleLinkedList : public ListBase<T> {
boolean add();
boolean remove(T* obj);
...
...
}
--
Issac Alphonso <ija1@ece.msstate.edu> <http://www.ece.msstate.edu/>
Mississippi State University, Mississippi 39762