oct-file memory management

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

oct-file memory management

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
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);
    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?


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