The Declaration of the VMatrix Class

The virtual matrix VMatrix class is created by the following declaration

class VMatrix : private vdoub
 {

 protected:
   unsigned signature;
   long mindex( int i, int j){
        return   (long) (((long)(i-1))*((long)c)+((long)(j-1))) ; }
   long curvecind;       // current index for vector
   strtype name;
   void SetupVectors( int rr=1, int cc=1 );
   void PurgeVectors( void );
   void Replace( VMatrix &ROp );
   void NewReference(VMatrix &ROp );

 public:

   double Nrerror( const char *errormsg );
   void Garbage( const char *errormsg);
   void Garbage( void ){ Garbage(" ");}
   int r,c;

   double m( int i, int j ) {          // get a value
       if( i<1 || j<1 || i>r || j>c ){
       cerr << "index out of range\n";
       exit(1);
       }
       curvecind = mindex(i,j);
       return v( curvecind );
   }
   VMatrix& M( int i, int j ) { // load current buffer
        curvecind = mindex(i,j);
        vdoub::operator[](curvecind);
        return *this;
   }

   VMatrix( void );            // constructors and destructors
   VMatrix( const char *str, int i, int j);
   VMatrix( VMatrix &ROp );
   ~VMatrix( void );

   double operator = ( double d ){     // write in a value
     vdoub::operator[](curvecind) = d;
     return d;
   }
   void operator= (VMatrix &ROp);

   void Nameit( const char *str ) { name = str; }
   void Nameit( VMatrix &mat ){ name = mat.name; }
   void Nameit( strtype newname){ name = newname; }
   strtype Getname( VMatrix &mat){ return mat.name; }
   void Showname( void ){ name.Showname(); }
   char *StringAddress( void ) { return name.StringAddress(); }

   void LoadMat(void);
   void DisplayMat(void);
   void InfoMat( void );
   void Writeb (char *fid, VMatrix &mat);

   friend VMatrix& operator+ (VMatrix &LOp, VMatrix &ROp);
   friend VMatrix& operator+ (double scalar, VMatrix &ROp);
   friend VMatrix& operator+ (VMatrix &ROp, double scalar);
   friend VMatrix& operator- (VMatrix &LOp, VMatrix &ROp);
   friend VMatrix& operator- (double scalar, VMatrix &ROp);
   friend VMatrix& operator- (VMatrix &ROp, double scalar);
   friend VMatrix& operator- (VMatrix &ROp);
   friend VMatrix& operator* (VMatrix &LOp, VMatrix &ROp);
   friend VMatrix& operator* (double scalar, VMatrix &ROp);
   friend VMatrix& operator* (VMatrix &ROp, double scalar);
   friend VMatrix& operator% (VMatrix &LOp, VMatrix &ROp );
   friend VMatrix& operator/ (VMatrix &LOp, VMatrix &ROp);
   friend VMatrix& operator/ (VMatrix &ROp, double scalar);
   friend VMatrix& operator/ (double scalar, VMatrix &ROp);
};

The in-ram version has a very similar structure, but is not derived from any other class. The system supplies dynamic memory so there is no need to encapsulate the memory manager in a separate class. In the in-ram version, matrices are constructed from vectors allocated on the heap. The in–ram vdoub counts the number of references to the vector. The vector is not freed until the number of references is zero.