[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory management in .oct files

From: John W. Eaton
Subject: Re: Memory management in .oct files
Date: Tue, 22 Mar 2005 20:09:12 -0500

On 22-Mar-2005, Richard Hindmarsh <address@hidden> wrote:

| John W. Eaton wrote:
| >On 19-Mar-2005, Richard Hindmarsh <address@hidden> wrote:
| >
| >| I guess this means that you decided not to impelemt e.g.
| >| 
| >|      xout1(ic1,ir1) = xin1(ir1,ic1); 
| >| 
| >| using a helper class.
| >
| >In what way are you suggesting using a "helper class" and what do you
| >mean by that?
| >  
| >
| I learnt the technique from
| From: Corey Kosak 
| [...]
| Date: 1998/11/22
| This is the only way I know to distinguish an lvalue from a rvalue - 
| maybe there are some others?

I don't know of one.  This technique is also described in James
Coplien's Advanced C++ book published in 1992 but is probably older
than that.

Earlier versions of Octave's Array classes had code like this but it
was (mostly) abandoned because of the complexity.  You can still find
an example of it in the DiagArray2.h file, where there is the
following comment:

  // A two-dimensional array with diagonal elements only.
  // Idea and example code for Proxy class and functions from:
  // From: address@hidden (James Kanze)
  // Subject: Re: How to overload [] to do READ/WRITE differently ?
  // Message-ID: <address@hidden>
  // Sender: address@hidden
  // Date: 29 Nov 1993 14:14:07 GMT
  // --
  // James Kanze                             email: address@hidden
  // GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France

so apparently I was aware of this article but not aware that it was
described in Coplien's book, which I found quite dense and hard to
understand way back then.  (Amazingly, Google makes the article
available again -- where did they dig up the tapes?)

Anyway, it is not enough to overload only operator=.  You also need to
overload +=, -=, *=, etc.  And then you can't just do it once in the
base class.  The code must be repeated in each derived class.  It did
not seem worth the effort.  But maybe you see a clean way to implement
this in a reliable way (without a great deal of code duplication, or
at least managing the duplication in a sane way with templates or
macros) so that it will work and also result in something that is
possible to maintain?


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]