But doing things this way, I'm making extra copies of A and B, no?
Is there a way of passing A and B to function1 without making those
unwanted copies? If it is of any importance, I just want to read the values
of A and B in function1, I don't need to change them there...
BTW, when writing something like:
I suppose here also is made a copy of args(0)? Can I avoid this copy (but I
still want to read the values in args(0) of course...) So can I do
something like :
| 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
| 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);