Hello everyone,
I have an issue with dispatching classes in GNU Octave 8.4 on Windows
10. I installed it via the x64 exe installer.
I am trying to call a c++ function in GNU octave, so I use a dispatcher
*.cc file as follows, which I then successfully compile into an oct-file:
mkoctfile my_dispatcher_function.cc -c
mkoctfile my_dispatcher_function.o my_cpp_class_pimpl.o -lquadmath
#include<octave/oct.h>
#include<octave/dNDArray.h>
/* body and inline-members of My_cpp_class */
DEFUN_DLD(my_dispatcher_function, args, nargout,
"Debugging_my_dispatcher_function_suitable_name"){
//
// flag = My_cpp_class.my_cpp_function();
//
// ++++ possess an instance
static My_cpp_class my_class_instance; // I also tried without
"static", i.e. re-instantiating at each call. Same behaviour (i.e.
octave closes).
//
// ++++ acquire arrays
NDArray array_x = args(0).array_value();
NDArray array_y = args(1).array_value();
//
// ++++ load inputs into class
for(int i=0;i<10;++i){ my_class_instance.x[i] = array_x(i); }
//
// ++++ compute
my_class_instance.compute();
//
// ++++ export outputs
for(int i=0;i<20;++i){ array_y(i) = my_class_instance.y[i]; }
//
// ++++ pack and return result
octave_value_list retval;
//
retval.append( octave_value(array_y ) );
return retval;
}
The Octave code, which calls the oct file, is:
assert( size(x)==[10,1] && size(x)==[20,1] ); % this passes successfully
y = my_dispatcher_function(x,y);
The constructor of My_cpp_class relies on a singleton, which has been
implemented with a non-member function that returns a static instance of
the Singleton.
Everytime I call the dispatcher from Octave GUI, Octave immediately
closes all windows of the software and ends. (Maybe a subgroup of us can
agree that either my class leaks or Octave encounters a bug. I have
debugged my class. I would appreciate avoiding a discussion into that area.)
I do not know or want to know or discuss whether this is a bug.
I am interested in acquiring a means to doing what the above code would
be expected to do under reasonable naive assumptions (which are: I have
a class. I can construct and destruct instances of it in c++ multiple
times without memory leaks. Each instance has buffers x,y and a member
function compute that manipulates y. I want to obtain y in Octave from
given x in Octave).
Currently, my work-around is to write a text file in octave, then make a
system call from octave to my cpp exe, this manipulates the textfile,
and octave reads the results. The issue is with speed of execution,
since the write to harddrive introduces enourmous latency, particularly
since I need ~10000 evalations per use case.
Thank you for any help.
Kind regards,
Guido