Hello, I am writing an oct-file interface to make a c library available
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);
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
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
3) If the user press CTRL-C, the script or function executing in octave will
before memory is freed. Is the unwind_protect statement enough to avoid