help-octave
[Top][All Lists]
Advanced

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

Re: loadlibrary... again


From: Jose
Subject: Re: loadlibrary... again
Date: Fri, 22 Nov 2013 01:01:17 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130106 Thunderbird/17.0.2

On 21/11/13 18:48, Michael Goffioul wrote:
On Thu, Nov 21, 2013 at 11:44 AM, marcimatz <address@hidden> wrote:

Thank you for your reply Michael,

Maybe my question was formulated in a too complicated way:

Between individual calls to a shared library function, will variables and
reserved resources be maintained?

If one of my shared library API function is:

xxx_incrementAndPrint()
{ // this is a C function inside of my shared library
     static int variable1=0;
     variable1++;
     printf("variable1=%i\n",variable1);
}

and I call that function via an oct file, within Octave:

oct_incrementAndPrint()
oct_incrementAndPrint()
oct_incrementAndPrint()

will the result be:

variable1=1
variable1=1
variable1=1

or

variable1=1
variable1=2
variable1=3

?


The best is to try it out :)

But I believe the actual result will be the second one. If you "clear" the
function table, then it should unload the library, and reload it on the
next call. So your internal counter would then restart from 1.

My belief is the same as Michael's.

Let me explain one example of something once I played with, just in case it helps. To me it sounds that you are trying to do something similar.

Once I had to do some real time computations in octave with data gathered asynchronously from several remote machines. I then created a C++ library to take care of all the communication hassle (reception, buffering and sending results back), and even some pre-filtering, all in real time.

The high level interface of the library was a class with a few high level methods (the typical connect, get_data, send_result and disconnect). I then created a mex interface to this class, with which I could create objects of this class, call the methods of particular objects and destroy them, all from within octave. After creating an object, the mex interface returns a pointer to the created object, and that pointer can be stored in octave as any other variable (using some tricks, see below). Whenever I want to call a method of that object, I then pass to the mex interface the pointer to that object and the name of the member function to be executed. The mex interface will then use cast the pointer to the appropriate type and call the required method from the pointed object. Note that there is no need to load any library of new function in octave after every call.

Upon instantiation, the class from my library spans internally different processes and calls other libraries to do all what it needed to do, all in real time and working in parallel to octave. While octave was doing its stuff in its process, the lib, in its own processes, was receiving, preprocessing, buffering the data and etc. Upon calling the get_data() method from the octave command line, the lib would then return all the buffered data that arrived since the previous call to the get_data method. Simple programming, nothing special.

Referring to your reformulated question: the point here is that octave did not touch the object "by itself" until I was exiting octave, and I could use the same particular object all the time in different calls. I only had to create the object once, let its processes run in parallel to octave and interact with it every now and then, and octave always "respected" the object ;). I did not try to clear the function table, though.

Hope this helps.


Regards.
J.

PD: as a reference. I used Tim Bailey's "Mex Object Handle" to store pointers in octave. It worked very nicely for me.
http://www-personal.acfr.usyd.edu.au/tbailey/software/other.htm
The following thread might also be useful
http://octave.1599824.n4.nabble.com/Passing-pointers-from-mex-gt-octave-gt-mex-td3901339.html




reply via email to

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