From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

When calling a function in a shared library, are parameters copied locally?

Solved!
Go to solution

I have a shared library with a function whose header is:

 

void __cdecl nextevent(double Input[], int32_t len);

 

When called it sends the values in Input[] to the control Input:

 

vi2.png

This vi is compiled to a DLL which uses the header above.

 

My question now is: Which of these operations is the correct one:

 

1. The Input control is a reference to the array Input[], no values are copied.

 

2. The values in the array Input[] are copied to the control Input, the local copy is used by the vi, then the values in the local copy are removed/deallocated.

 

It seems reasonable to me that 1 is the correct one, but I can't be sure, and I can't think of any way to check it.

 

Lars Melander
Uppsala Database Laboratory, Uppsala University
0 Kudos
Message 1 of 2
(2,017 Views)
Solution
Accepted by topic author LarsM

For this particular case option 2 is valid. The reason is that LabVIEW arrays are not just pointers to a memory location but handles. And there is no legal way to create valid LabVIEW handles from an C runtime allocated memory pointer. So LabVIEW converts the incoming array pointer into a handle which is basically nothing else than allocating the handle with a size large enough to  hold all array data, and then copies the data from the array pointer into this handle. After the call, the handle is properly deallocated.

Rolf Kalbermatter
My Blog
Message 2 of 2
(2,002 Views)