help-octave
[Top][All Lists]
Advanced

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

Re: Persisting data between calls to OCT file


From: c.
Subject: Re: Persisting data between calls to OCT file
Date: Tue, 1 Apr 2014 23:28:59 +0200

On 1 Apr 2014, at 21:18, Susnak <address@hidden> wrote:

> Hello,
> I could not find the answer anywhere so I hope nobody will be offended if I
> ask here. 
> So here it goes:
> 
> Is there a way how to make some data persist between calls to oct file? In
> Matlab MEX files there are
> mexMakeArrayPersistent
> and
> mexMakeMemoryPersistent
> which do exactly that. 
> 
> I guess it would be sufficient for me just to have a way to register an
> atExit function as in
> mexAtExit,
> since I can store a pointer in a static variable and register a cleanup
> function by mexAtExit.
> 
> Thank you for any comment.
> 
> Zdenek

well, I'm not sure I understand what you mean, but isn't it sufficient to 
declare a variable "static"?

#include <octave/oct.h>

static double p = 0;
DEFUN_DLD(pippo, args, nargout, "pippo\n")
{
  octave_value_list retval;
  int nargin = args.length ();

  if (nargin < 1) 
    retval(0) = p;
  else
    p = args(0).double_value ();

  return retval;
}


>> pippo
ans = 0
>> pippo(2)
>> pippo
ans =  2
>> 


If you want something more complex, you can define a new Octave class following 
the example described in this presentation:
http://wiki.octave.org/wiki/images/b/b0/Slides_octconf_gdf_jgh.pdf

c.


reply via email to

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