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]

Re: polymorphism - virtual memory exhausted


This code is not quite what we need to track down the problem.  A
preprocessed .ii file would be better.  Use -save-temps on the compile
line to leave one.

-eric


> 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

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