.oct files - keeping state across calls
Christophe Tournery
christophe.tournery at illusonic.com
Mon Jul 6 07:18:58 CDT 2009
Hi all,
I am looking for a best practice advice regarding .oct files in octave
3.2
Description:
------------
I am writing an oct file wrapper around a C library. The library
performs block processing of audio files (similar to fft block
processing). However the library needs to keep its internal state
across calls to its "process" function. Therefore I am using an init
function to initialize this internal state and return a handle to it,
such that multiple instances of the library can be used at the same
time. Usage in octave is in pseudo code:
handle = mylib_init()
for (...)
y = mylib_process(handle, x)
...
end
mylib_destroy(handle)
The oct file (.cc) must keep track of the allocated handles and
internal states which are C structures. One way of doing it is to get
rid of the handle and return the internal state in octave's user
space. However those can be a bit large and are useless to the caller
so I'd rather keep them hidden inside the oct file, hence the handle
which reduces complexity and improves performance by avoiding
unnecessary copies of data.
Problem:
--------
Both mylib_init() and mylib_process() must share a list of allocated
handles and internal states of mylib. In octave 3.0 I used a static
std::map in my .cc file for the handles and that worked. In octave 3.2
this fails. It seems that in 3.2 the .oct file is loaded twice, once
for mylib_init() and once for mylib_process(), therefore the static
variable trick does not work anymore since they have different
addresses.
Any suggestions?
Thanks in advance
Christophe Tournery
More information about the Help-octave
mailing list