Matlab的墨西哥图书馆的生命周期 [英] Matlab Mex library lifecycle
问题描述
有谁知道MATLAB MEX库的生命周期是什么?特别是我感兴趣的是以下内容:
Does anyone know what the matlab mex library lifecycle is? Specifically I am interested in the following:
- 有没有办法迫使库调用它之前加载?
- 是库中的单或多个实例加载?
- 是否有任何初始化钩子调用之前?
- 是否有当卸载库进行清理,可截取析构挂钩/信号?
我在这里并没有在网上广泛的搜索,我无法找到这些问题的答案。我的问题与初始化一些性能成本,我想避免,如果可能的话,而不需要编写的服务。
I did an extensive search here and online and I could not find the answers to these questions. My problem has some performance cost with initialization and I would like to avoid that if possible, without needing to write a service.
推荐答案
正如我在评论中提到,在Windows中你可以实现<一个href=\"http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583.aspx\"><$c$c>DllMain$c$c>入口点。这是因为MEX文件是不同后缀只是普通的DLL文件。下面是一个小例子:
As I mentioned in the comments, in Windows you could implement DllMain
entry point. This is because MEX-file are just regular DLL files with different extension. Here is a minimal example:
#include "mex.h"
#include <windows.h>
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
mexPrintf("DLL_PROCESS_ATTACH: hModule=0x%x\n", hModule);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
mexPrintf("DLL_PROCESS_DETACH: hModule=0x%x\n", hModule);
break;
}
return TRUE;
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mexPrintf("Inside MEX-function\n");
}
下面是如何工作的:
>> mex -largeArrayDims testDLL.cpp
>> testDLL
DLL_PROCESS_ATTACH: hModule=0xa0980000
Inside MEX-function
>> testDLL
Inside MEX-function
>> clear testDLL
DLL_PROCESS_DETACH: hModule=0xa0980000
这篇关于Matlab的墨西哥图书馆的生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!