octave: Function Locking

 
 11.9.6 Function Locking
 -----------------------
 
 It is sometime desirable to lock a function into memory with the ‘mlock’
 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 ‘clear’ does not remove this initialization.
 
    As an example,
 
      function my_function ()
        mlock ();
        ...
 
 prevents ‘my_function’ from being removed from memory after it is
 called, even if ‘clear’ is called.  It is possible to determine if a
 function is locked into memory with the ‘mislocked’, and to unlock a
 function with ‘munlock’, which the following illustrates.
 
      my_function ();
      mislocked ("my_function")
      ⇒ ans = 1
      munlock ("my_function");
      mislocked ("my_function")
      ⇒ ans = 0
 
    A common use of ‘mlock’ is to prevent persistent variables from being
 removed from memory, as the following example shows:
 
      function count_calls ()
        mlock ();
        persistent calls = 0;
        printf ("'count_calls' has been called %d times\n",
                ++calls);
      endfunction
 
      count_calls ();
      ⊣ 'count_calls' has been called 1 times
 
      clear count_calls
      count_calls ();
      ⊣ 'count_calls' has been called 2 times
 
    ‘mlock’ might equally be used to prevent changes to a function from
 having effect in Octave, though a similar effect can be had with the
 ‘ignore_function_time_stamp’ function.
 
  -- : mlock ()
      Lock the current function into memory so that it can’t be cleared.
 
DONTPRINTYET       See also: Seemunlock XREFmunlock, *notemislocked:
DONTPRINTYET       See also: Seemunlock XREFmunlock, Seemislocked

      XREFmislocked, Seepersistent XREFpersistent.
 
  -- : munlock ()
  -- : munlock (FCN)
      Unlock the named function FCN.
 
      If no function is named then unlock the current function.
 
      See also: Seemlock XREFmlock, Seemislocked XREFmislocked,
      Seepersistent XREFpersistent.
 
  -- : mislocked ()
  -- : mislocked (FCN)
      Return true if the named function FCN is locked.
 
      If no function is named then return true if the current function is
      locked.
 
DONTPRINTYET       See also: Seemlock XREFmlock, Seemunlock XREFmunlock, *noteDONTPRINTYET       See also: Seemlock XREFmlock, Seemunlock XREFmunlock, See
      persistent XREFpersistent.