LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Making a LVDLL and call it from C, containing clusters and Arrays of Clusters

Solved!
Go to solution
Solution
Accepted by topic author JonasM

There are only two possibilities that the FGV could be garbage collected without explicitedly closing your refs:

 

1) The user explicitly loads and unloads the DLL through calls to LoadLibrary() and FreeLibrary(). Once FreeLibrary() has been called the same number of times as LoadLibrary() for any specific library, it is forcefully unloaded from memory and that will cause the LabVIEW runtime to also deallocate any "objects" you created in that library. I say here "objects" in the broadest sense, meaning anything that maintains some dataspace, including an FGV storing something in an unitialized shift register.

 

2) The user statically links to your DLL by linking it with the provided lib file but places the code in its own loadable DLL that he loads and unloads at will. Once he unloads his module it will forcefully unload the LabVIEW DLL too, and then everything in it will be gone.

 

But typically, any experienced C(++) programmer knows that data that gets allocated by a DLL internally, will be gone for good, once that DLL gets explicitedly unloaded. So it should not be a surprise to such a programmer that references (handles) or whatever you intend to call those things in your library interface, won't survive an explicit library unload.

 

One recommendation though: You currently do a lookup in the GetRef() method of the FGV, which is typically the one method that is called the most. It would be better to simply create a reference (object) once and store it in an array of references and then return the index into that array as your refnum that the user passes to all other functions. That way the GetRef() method is a cheap Index Array function only.

To make sure indices don't move, once they were created, you need to do a little more work in the create and close method. Create searches the array for an empty (Not an Object) slot and if found simply assigns the newly created object in there and returns that index. Otherwise it appends a new element to the array and returns its index. The Close method deallocates the object and zeros out the element in the array to indicate that it is now free. This avoids that indices beyond the current index get invalidated by moving up everything to fill up the empty spot, and also avoids very intense array resizing all the time and makes a very cheap GetRef() method too.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 11 of 13
(659 Views)

Thanks rolfk, i thought that was the case, I will document the need to keep dll loaded for as long data need to be stored.

 

about the obj ref fgv, I will implement that soon. This was just a quick fix in the first place. It was a bit over 40% slower than directly calling the get method. So the for loop will slow the methods down, how ever. We are likely only going to see at most 4 objects so the loop should be complete in a few us. But index array is for sure faster

Best regards
JM, LabVIEW CLA
0 Kudos
Message 12 of 13
(651 Views)

Hola buen día, tengo problemas para mandar llamar una dll en c# creada en labview, no tengo idea de como hacerlo, algun codigo que me recomiendes?

0 Kudos
Message 13 of 13
(358 Views)