octave-maintainers
[Top][All Lists]
Advanced

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

Reducing memory by emulating IDL's temporary() function


From: John W. Eaton
Subject: Reducing memory by emulating IDL's temporary() function
Date: Thu, 24 Apr 2008 16:09:02 -0400

On 24-Apr-2008, Judd Storrs wrote:

| Hello,
| 
| I previously posted to octave-help about IDL's temporary() function which
| can be used in IDL to reduce memory duplications in some situations. The
| documentation for IDL's function can be found at
| http://idlastro.gsfc.nasa.gov/idl_html_help/TEMPORARY.html
| 
| >From the summary:
| 
| "The TEMPORARY function returns a temporary copy of a variable, and sets the
| original variable to "undefined". This function can be used to conserve
| memory when performing operations on large arrays, as it avoids making a new
| copy of results that are only temporary. In general, the TEMPORARY routine
| can be used to advantage whenever a variable containing an array on the left
| hand side of an assignment statement is also referenced on the right hand
| side."
| 
| I've cobbled together a DLM that tries to replicate this behavior in octave
| (code at bottom of message). Here's the code I'm using for testing it:
| 
| % Baseline
| A = zeros(4096,4096);
| B = zeros(4096,4096);
| A = A + B + B;
| 
| % Using temporary()
| A = zeros(4096,4096);
| B = zeros(4096,4096);
| A = temporary("A") + B + B;
| 
| Right now, temporary() takes a string, because I haven't figured out how to
| find the symbol_record of the parameter.
| 
| I think it may be working -- I used the gnome-system-monitor graphs and
| increased the matrix sizes until I could see the bumps in the graphs. Using
| the baseline code I think I see the memory use step up three times. Using
| temporary it only steps up twice. Is there a better way to monitor octave's
| memory use?
| 
| --judd
| 
| 
| temporary.cc:
| 
| #include <oct.h>
| 
| extern OCTINTERP_API symbol_table *curr_caller_sym_tab;
| 
| DEFUN_DLD(temporary, args, ,
|           "Try to remove a variable from the caller scope and also return
| it.")
| {
|   std::string name = args(0).string_value();
|   symbol_record * ptr;
|   ptr = curr_caller_sym_tab->lookup(name);
|   octave_value retval = ptr->def();
|   ptr->clear();
|   return retval;
| }

Given this definition, what happens if you write

  A = something;
  A = temporary ("A") + A

?

Also, since you are accessing the symbol table, your code will not
work with Octave 3.1 since the symbol table code in Octave has been
completely rewritten since 3.0 in order to support Matlab compatible
classes.

jwe


reply via email to

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