mexhandle

所属分类:matlab编程
开发工具:Visual C++
文件大小:5KB
下载次数:4
上传日期:2006-12-08 00:59:45
上 传 者sunxiaodian
说明:  you can pass C++ objects between different MEX functions without first converting to a MatLab compatible format
(you can pass objects between different C ME X functions without first converting to a MatLa b compatible format)

文件列表:
mex_create.cpp (259, 2004-05-13)
mex_destroy.cpp (234, 2004-05-13)
mex_handletest.cpp (1741, 2004-10-21)
ObjectHandle.h (6051, 2004-10-21)

MatLab MEX ObjectHandle -------------------------- This utility allows you to create a C++ object within a mex-file and to pass a handle to this object back to MatLab. Thus, you can pass C++ objects between different MEX functions without first converting to a MatLab compatible format. Basic Usage ----------- The ObjectHandle comes with a set of wrapper functions, which simplify the common case. template mxArray *create_handle(T* t); template T& get_object(const mxArray *mxh); template void destroy_object(const mxArray *mxh); These are demonstrated in mex_handletest.cpp. More Advanced Usage ------------------- To provide more control over the C++ object being handled, can use ObjectHandle directly. These operations are also demonstrated in mex_handletest.cpp. A particular use is to pass a static object to a handle. eg, static MyObject obj; ObjectHandle *objh = new ObjectHandle(obj); mxArray *mex_handle = objh->to_mex_handle(); In the above case, since obj is passed as a reference, the ObjectHandle does *not* own obj, and will not automatically destroy it. Examples -------- 1. mex_handletest.cpp Simple example where a C++ object is handed back and forth between a single mex-dll. The mex-function is passed a flag to indicate what operation is to be carried out. If the user calls 'clear all' or 'clear mex' or 'clear functions' from within MatLab, the C++ object is destroyed automatically, and the handle ceases to be valid. 2. mex_create.cpp and mex_destroy.cpp An simple example where a C++ object is created in one mex-dll and passed to another, where it is destroyed. (See "known issues" below.) Again, the object is destroyed automatically if the dll is cleared. Known Issues ------------ Some memory models with MSVC++ appear to cause problems with this utility. Specifically, to pass a handle from one MEX-dll to another, the dlls *must* share a common address-space. Make sure that your MEX setup uses appropriate run-time configuration to ensure shared address-space. Note, if you are simply passing a C++ object back-and-forth between MatLab and a single MEX-dll, then there is no problem.

近期下载者

相关文件


收藏者