Rank: 46977 based on 0 downloads (last 30 days) and 0 file submitted
photo

Greg

E-mail
Company/University
Gulfstream Aerospace

Personal Profile:
Professional Interests:
Aerodynamics

 

Watch this Author's files

 

Comments and Ratings by Greg View all
Updated File Comments Rating
03 Jan 2014 Example MATLAB class wrapper for a C++ class An example of how to safely encapsulate a C++ class in a MATLAB class, via a mex interface. Author: Oliver Woodford

Very useful code!

Found some interesting behavior though.

From my observations, as far as the operating system is concerned, all mex-files that you call from a single instance of MATLAB share the same memory segmentation. That is, you can create a C++ object in one mex-file, pass the handle to that object back into MATLAB, then delete the object in a different mex-file. This seems to work just fine and is handy in the case where the code of one class creates instances of another class.

This gets funky with the calls to mexLock() and mexUnlock() though. mexLock and mexUnlock are automatically keyed to the currently-running mex-file. So, if an object of Class_B is created inside Class_A_mex and convertPtr2Mat is called to pass that pointer back to MATLAB, you've just added an extra lock to Class_A_mex that won't be unlocked when Class_A is deleted. The Class_B_mex delete method seems to delete the Class_B object just fine, but it doesn't know anything about the mexLock on Class_A_mex.

For the moment, I've created a workaround by creating a "convertPtr2MatLockless" function in "class_handle.hpp" that's an exact copy of "convertPtr2Mat" except that it doesn't call mexLock(). I call the "Lockless" version whenever creating an object of a different class than the one the mex file is for.

I'm not all that happy with that workaround, but I don't really know how important the mexLock() is. At the very least, it doesn't appear to be necessary to keep the C++ delete methods from causing segfaults.

02 Jan 2014 Example MATLAB class wrapper for a C++ class An example of how to safely encapsulate a C++ class in a MATLAB class, via a mex interface. Author: Oliver Woodford

23 Jun 2010 Model3d MATLAB class for reading, viewing 3D dxf and 3ds files. Author: Steven Michael

This code uses old-style (pre-2008a, I believe) object-oriented programming. As far as I can tell, that makes it pretty much non-functional in any newer version of Matlab.

09 Jun 2010 MESH2D - Automatic Mesh Generation Generates unstructured triangular meshes for general 2D geometry. Author: Darren Engwirda

I love your code, but I've recently begun some efforts to see if I can't speed up the runtime a bit.

Is there a particular reason why "mydelaunayn.m" uses the "delaunayn" function instead of the "delaunay" function? As far as I can tell on my machine (with Matlab 7.10), "delaunay" is around four times faster than "delaunayn" and the code seems to function just fine when I make the replacement.

Contact us