engPutVariable()...how long and what workspace

5 views (last 30 days)
I'm trying to use engPutVariable and engGetVariable to transfer blocks of data between C and a Matlab engine.
Two related questions.
First if I create an engine pointer and then a mxArray in C and use mxGetPr or GetVariable for say a real DP array, and the pull function returns, is this blocking or non-blocking? Is this supposed to mean that the source Matlab base workspace variable or array is now in a complete, valid copy in C memory?
Second, how does this still work if I just open the engine but do not actually use say engExecuteString(), but still use mxPut-style calls to push data from C to Matlab? I'm wondering just how long after the mxPut returns in C, do I have to wait before I can rely on the data-transfer being complete in Matlab. Is there some relation between time and the size in Bytes of the transfer?
thanks

Answers (1)

Maneet Kaur Bagga
Maneet Kaur Bagga on 5 Jan 2024
Hi Samuel,
For the workaround of your first question:
  • When you use "mxGetPr" on an "mxArray" to access the real double-precision (DP) data, this operation is blocking. It provides a pointer to the real data elements of the "mxArray". This operation is immediate and does not involve any data transfer, as it simply returns a pointer to the data already present in the mxArray. The data is valid and can be used right away in your C code.
  • When you use "engGetVariable" to retrieve a variable from the MATLAB engine workspace, this operation is also blocking. It will not return until the data has been fully copied from MATLAB's workspace into the mxArray in your C program. After "engGetVariable" returns, you have a complete and valid copy of the MATLAB variable in your C memory, encapsulated within an mxArray.
For the second part of the question:
  • When you open a MATLAB engine session from C using the engine functions like "engOpenSingleUse", you're creating a communication link between your C program and a MATLAB process. This allows you to transfer data to and from MATLAB, execute MATLAB commands.
  • When you use "engPutVariable", you do not need to wait after the function returns; the data is immediately available in MATLAB's workspace for use. The transfer time is not exposed to you as the programmer, as the blocking nature of the function ensures the data is ready when the function call is complete. There is no direct relationship between time and the size of the transfer that you need to manage in your code.
Please refer to the following MATLAB Documentation for better understanding:
Hope this helps!

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!