c++ - MATLAB MEX interface to a class object with multiple functions -


I am using the MEX interface to run the C ++ code in MATLAB. I would like to add many functions to MATLAB for dealing with sysSetAttribute (name, value) string = sysGetAttribute (value) to system object:

  sysInit () sysRefresh Each MEX DLL can include a function, so I need to find a way to store the indicator in the global  system  object, which will remain in existence until it will not be removed  sysExit < / Code> by calling. 

How can I do this correctly in MATLAB? Are there any ways to call Global Porter to call in MEX work?

A common way is to provide m-file functions that provide a public interface, such as SysInit.m, sysRefresh .m, etc.

Each of these M-Fixes identifies the function to call the Mexico function with any type of handle, a string (or number), and any additional aggregates for example, sysRefresh. M can look like this:

  function sysRefresh (handles) reverse systemmax (handles, 'refresh')  

In your sysMex mex function, you can Either a raw pile indicator might be (easy but not very secure), or you can use C / Maintain mapping in C ++ with the handle ID for the real object pointer. This solution requires a little extra work, but it is very safe, in such a way, by mistake, one can not give an arbitrary number as a handle, which acts as a drop indicator. Also, you can work like fancy things like using the on-Kleinop function to release all memory and resources while unloading Mac Function (for example, when you re-compiling Mac fax, restart the mailbox. Do not need to be)

If you want you can go a little further and hide handles behind the matlab class. If you are interested, then read the OO features for Matlab in the dots. If you are using the latest version, you can take advantage of their very cleaner handles object.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -