File: Function-Locking.html

package info (click to toggle)
octave3.2 3.2.4-8
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 62,936 kB
  • ctags: 37,353
  • sloc: cpp: 219,497; fortran: 116,336; ansic: 10,264; sh: 5,508; makefile: 4,245; lex: 3,573; yacc: 3,062; objc: 2,042; lisp: 1,692; awk: 860; perl: 844
file content (133 lines) | stat: -rw-r--r-- 5,903 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<html lang="en">
<head>
<title>Function Locking - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Function-Files.html#Function-Files" title="Function Files">
<link rel="prev" href="Overloading-and-Autoloading.html#Overloading-and-Autoloading" title="Overloading and Autoloading">
<link rel="next" href="Function-Precedence.html#Function-Precedence" title="Function Precedence">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Function-Locking"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="Function-Precedence.html#Function-Precedence">Function Precedence</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Overloading-and-Autoloading.html#Overloading-and-Autoloading">Overloading and Autoloading</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Function-Files.html#Function-Files">Function Files</a>
<hr>
</div>

<h4 class="subsection">11.7.5 Function Locking</h4>

<p>It is sometime desirable to lock a function into memory with the
<code>mlock</code> function.  This is typically used for dynamically linked
functions in Oct-files or mex-files that contain some initialization,
and it is desirable that calling <code>clear</code> does not remove this
initialization.

   <p>As an example,

<pre class="example">     mlock ("my_function");
</pre>
   <p class="noindent">prevents <code>my_function</code> from being removed from memory, even if
<code>clear</code> is called.  It is possible to determine if a function is
locked into memory with the <code>mislocked</code>, and to unlock a function
with <code>munlock</code>, which the following illustrates.

<pre class="example">     mlock ("my_function");
     mislocked ("my_function")
      ans = 1
     munlock ("my_function");
     mislocked ("my_function")
      ans = 0
</pre>
   <p>A common use of <code>mlock</code> is to prevent persistent variables from
being removed from memory, as the following example shows:

<pre class="example">     function count_calls()
       persistent calls = 0;
       printf ("'count_calls' has been called %d times\n",
               ++calls);
     endfunction
     mlock ("count_calls");
     
     count_calls ();
     -| 'count_calls' has been called 1 times
     
     clear count_calls
     count_calls ();
     -| 'count_calls' has been called 2 times
</pre>
   <p class="noindent">It is, however, often inconvenient to lock a function from the prompt,
so it is also possible to lock a function from within its body.  This
is simply done by calling <code>mlock</code> from within the function.

<pre class="example">     function count_calls ()
       mlock ();
       persistent calls = 0;
       printf ("'count_calls' has been called %d times\n",
               ++calls);
     endfunction
</pre>
   <p><code>mlock</code> might equally be used to prevent changes to a function from having
effect in Octave, though a similar effect can be had with the
<code>ignore_function_time_stamp</code> function.

<!-- variables.cc -->
   <p><a name="doc_002dmlock"></a>

<div class="defun">
&mdash; Built-in Function:  <b>mlock</b> ()<var><a name="index-mlock-639"></a></var><br>
<blockquote><p>Lock the current function into memory so that it can't be cleared. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dmunlock.html#doc_002dmunlock">munlock</a>, <a href="doc_002dmislocked.html#doc_002dmislocked">mislocked</a>, <a href="doc_002dpersistent.html#doc_002dpersistent">persistent</a>. 
</p></blockquote></div>

<!-- variables.cc -->
   <p><a name="doc_002dmunlock"></a>

<div class="defun">
&mdash; Built-in Function:  <b>munlock</b> (<var>fcn</var>)<var><a name="index-munlock-640"></a></var><br>
<blockquote><p>Unlock the named function.  If no function is named
then unlock the current function. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dmlock.html#doc_002dmlock">mlock</a>, <a href="doc_002dmislocked.html#doc_002dmislocked">mislocked</a>, <a href="doc_002dpersistent.html#doc_002dpersistent">persistent</a>. 
</p></blockquote></div>

<!-- variables.cc -->
   <p><a name="doc_002dmislocked"></a>

<div class="defun">
&mdash; Built-in Function:  <b>mislocked</b> (<var>fcn</var>)<var><a name="index-mislocked-641"></a></var><br>
<blockquote><p>Return true if the named function is locked.  If no function is named
then return true if the current function is locked. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dmlock.html#doc_002dmlock">mlock</a>, <a href="doc_002dmunlock.html#doc_002dmunlock">munlock</a>, <a href="doc_002dpersistent.html#doc_002dpersistent">persistent</a>. 
</p></blockquote></div>

   </body></html>