On Jan 22, 9:55 pm, "newuser asdf" <sabine.schnei...@rolmail.net> wrote: > Hello, > > I have some problems in understanding, how this way of object address passing works in my concrete example... Perhaps someone can give me a hint, what I'm doing wrong? > > My task: I'm trying to create an instance of a C++ object in a mex file, which then should return its memory address, and another mex function (called afterwards) gets this address as a parameter and calls some functions on it.
Don't do that.
You are traversing at least two more layers of software interference than you would normally care about:
Your C++ function interacts with the OS to translate the pointer to a physical address in the RAM chips on the memory rack inside your computer. You usually don't care about this - the C++ compiler hides all the dirty details from the programmer.
When you return back to matlab, you enter a world where Java is a dominant player. As I understand it, the matlab user interface (where you access the workspaces etc) are programmed in Java, in which case the Java interpterer starts messing things up. And the Java interpterer, too, interacts with the OS. Not necessarily in exactly the same way that the C++ compiler does, though.
So in order to get back to the physical address where your C++ object resides, you need to *ensure* that whatever you do is robust with respect to the interaction of *both* the Java interpreter *and* the OS.
*Ensuring* that all this works is by no means easy if the system design is not intended for these kinds of things. Which matlab isn't.