help-octave
[Top][All Lists]
Advanced

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

Memory management in .oct files


From: Richard Hindmarsh
Subject: Memory management in .oct files
Date: Wed, 16 Mar 2005 19:33:08 +0000
User-agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.7.1) Gecko/20040707

If, in Octave, I do
%Step 1
a = rand(3000,3000);

%and then % Step 2
b = a;

the memory used does not increase hardly at all upon exectuation of Step 2 as presumably Octave only creates new memory b's data when it is written to.

However, it seems that when I run the matrixdemo.cc example in
http://perso.wanadoo.fr/prthomas/intro.html#matrixdemo
at some stage (perhaps the copy constructor #2, or is it the return statement #7) a third matrix is created in memory.
Could someone kindly inform me as to which of the two steps it is and how I can 
avoid creating unnecessary copies?

Another useful piece of information would be the Octave equivalent of (cout,endl) 
<-> (octave_stdout,?) so that I can
be sure that writes to the terminal correspond to the changes in memory usage I 
see.

I am using cygwin by the way.

Thanks,
Richard

#include <octave/oct.h>
DEFUN_DLD (matrixdemo, args, ,
"My first matrixdemo \n\n\
transpose_of_x=matrixdemo(x) \n") {
 octave_value retval;
if ( args.length() != 1 ) { // #1 error("this version of matrixdemo only takes one argument");
   return retval;
 }
 Matrix xin1( args(0).matrix_value() );                   // #2
 int ir = xin1.rows();                                    // #3
 int ic = xin1.cols();
 Matrix xout1(ic,ir);                                     // #4
 for (int ir1 = 0 ; ir1 < ir ; ir1++)                     // #5
   for (int ic1 = 0 ; ic1 < ic ; ic1++) {
     xout1(ic1,ir1) = xin1(ir1,ic1);                      // #6
   }
 return retval = xout1;                                   // #7
}



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

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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