LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C++ & dll & labview



@simon76 wrote:

Hi Rolf,

May I know what's the mean of "not done right with resource leaks and more" ??

regards



Well I have a personal distaste for global variables, both in LabVIEW and in C Smiley Wink. That said they can be useful at times.
And looking at your code I can't immediately see a problem with your use of global variables other than executing the Initialize function twice will probably create memory leaks as it would overwrite previously allocated memory pointers.

Global variables are "bad" for a number of reasons. For me they usually make the code hard to understand since you get data that can be accessed from anywhere at any time. In order to understand a potential problem that could be related to such a variable you have to look at every function that might access it in some ways.
Also they make code inherently unsafe for multi-threading. You can't allow LabVIEW (or any other caller) to call 1 function accessing a global variable while another function accessing that global variable is still executing. So for this reason I try to avoid global variables whenever possible except for internal resource tracking.

Your implementation is however feasable as long as you do not need concurrent access to the functions. Imagine some code executing the function to deallocate the pointers while another function is still running. Bad things will happen.

Your approach makes sense in so far that it simplifies greatly the interface to call from LabVIEW. The cost of this is that it never can scale if you need to allocate multiple objects and start to call certain functions concurrently in order to distribute the load (for instance if some functions would block for some reasons and you would want to use that CPU time to start another test task instead of burning it in an idle loop somewhere inside your call).

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
Message 21 of 21
(374 Views)