oct file destructor?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

oct file destructor?

Mike Miller-4
Hi,

Is there a way to register a destructor to be called when an oct file is
unloaded (via "clear all" or "clear functions")? Does anyone have any
thoughts on how to implement such a thing or a good pattern to follow?

I was thinking of trying a class destructor of a static object as a
stand in, something like

  struct cleanup_object
  {
    cleanup_object () {}
    ~cleanup_object () { uninitialize_something_important (); }
  };

  static cleanup_object obj;

Other suggestions? Thanks,

--
mike


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: oct file destructor?

John W. Eaton
Administrator
On 02/12/2018 02:48 AM, Mike Miller wrote:

> Hi,
>
> Is there a way to register a destructor to be called when an oct file is
> unloaded (via "clear all" or "clear functions")? Does anyone have any
> thoughts on how to implement such a thing or a good pattern to follow?
>
> I was thinking of trying a class destructor of a static object as a
> stand in, something like
>
>    struct cleanup_object
>    {
>      cleanup_object () {}
>      ~cleanup_object () { uninitialize_something_important (); }
>    };
>
>    static cleanup_object obj;
>
> Other suggestions? Thanks,

If the static object works for you, then maybe that's the simplest thing
to do?  Otherwise, we could maybe add something that would call a
function when Octave unloads the shared library.  Either in the
dynamic_library class (lowest level) or in the dynamic_loader class
(higher level, closer to .oct/.mex files).

jwe



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------