help-octave
[Top][All Lists]
Advanced

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

oct-file memory management


From: fibus
Subject: oct-file memory management
Date: Mon, 25 Jun 2018 08:45:57 -0700 (MST)

Hello, I am writing an oct-file interface to make a c library available
within octave.
The c library needs to dynamically allocate memory and this memory should be
persistent
and thus it should not be garbage collected. 

The interface 'foo'  is meant to be used in this way:
    
    % option is an octave structure
    ptr = foo('setup', options);
    z = zeros(100,1);
    for i = 1 : 100
        z(i) = foo('do_stuff', ptr);
    end
    foo('free', ptr);

The 'setup' command in the DEFUN_DLD gateway should convert the options
structure from octave to
a C structure and call the c library function foo_setup which set up memory
for its internals
and returns a pointer to the internal structure. 

I have the following questions:

1) how to manually allocate persistent memory in oct-files? That is, the
equivalent of 
    mxMalloc (mxCalloc)  | mexMakeMemoryPersistent | mxFree. 
    In the documentation it appears that with OCTAVE_LOCAL_BUFFER one
    can only allocate garbage collected memory. 

2) Which data type would be best to contain the output ptr in octave? I
though to use a
     scalar uint64NDArray...

3) If the user press CTRL-C, the script or function executing in octave will
be terminated
    before memory is freed.  Is the unwind_protect statement enough to avoid
memory leak?

regards.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



reply via email to

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