help-octave
[Top][All Lists]
Advanced

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

.oct files calling .oct files...


From: John W. Eaton
Subject: .oct files calling .oct files...
Date: Sat, 18 Oct 1997 13:01:03 -0500

On 18-Oct-1997, Stef Pillaert <address@hidden> wrote:

| I managed to translate a lot of my octave-scripts to C++-code, and there is
| indeed a very significant increase in speed....
| 
| But I have this little question...
| 
| Suppose I have a function1 (let's assume it needs two arguments, say A and
| B: retval=function1(A,B)) I have a .cc version of it, (and the
| corresponding oct-file...)
| 
| Next, I have a function2 (with tree arguments, say A, C and B).
| I want to call function1 from function2, and I do it like this:
| 
| DEFUNDLD (function2,args,nargout,
| "usage: retval=function(A,C,B) ")
| {
|  octave_value_list tmp
|  tmp(1)=args(2);
|  tmp(0)=args(0);
|  octave_value_list tmp_ret = Ffunction1 (tmp,1);
|  ....
| }
| 
| But doing things this way, I'm making extra copies of A and B, no?

No.  The array objects used to define octave_value_list use reference
counting to unnecesary copying of the actual data.  Copying should be
delayed until you try to modify the object.

| BTW, when writing something like:
| 
| ...
| Matrix Y=args(0).matrix_value()
| ...
| 
| I suppose here also is made a copy of args(0)?

No.  This is also handled with reference counting.  A copy shouldn't
happen unless the object is modified.

| Can I avoid this copy (but I
| still want to read the values in args(0) of course...) So can I do
| something like :
| double a=args(0).elem(5,6);

No, because there is no elem() operator defined for the octave_value
class.  You need to write either

  Matrix Y = args(0).matrix_value();
  double a = Y.elem(5,6);

or

  double a = args(0).matrix_value().elem(5,6);

jwe



reply via email to

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