How to share memory between C and MATLAB?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have developed a DLL in C language. I have 3 functions and a viriable in that DLL. I was able to load the library and also call the function in matlab. I have a C application which also uses the same DLL. But if the variable(in DLL) value is changed in C application its not reflected in MATLAB and vice-versa. Can anyone tell me how memory sharing between C and MATLAB can be achieved? So that if i change the value of a variable in library using C its changed value should be reflected in MATLAB and vice-versa.
0 comentarios
Respuestas (1)
James Tursa
el 12 de Jun. de 2013
Your C application and your MATLAB program are separate processes with their own separate address spaces. When each pulls in the DLL they do so within their own address spaces. Even though they are running the same "code" the address space the code is using is different for each.
The only thing on the FEX I am aware of related to this is the following submission by Joshua Dillon, which shares matrix data between two MATLAB sessions:
and this submission:
6 comentarios
James Tursa
el 15 de Jun. de 2013
Editada: James Tursa
el 15 de Jun. de 2013
The easy way to do this is to turn your C application into a mex function. I.e., load it as a dll into MATLAB. That way it will share the same address space as MATLAB and can access the same shared memory. The harder way is using something like Joshua Dillon's submission noted above.
Ver también
Categorías
Más información sobre MATLAB Compiler en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!