sm07 Posted July 27, 2007 Report Share Posted July 27, 2007 I have 2 or 3 VI's running in parallel (some may be sub-vi's of others) and i'm wondering how bad is it to use global variables in them. My needs are very simple. For example, in one program i am writing to variable X inside a while loop, and in a second program, I am using variable X to calculate variable Y. Honestly that's as simple as I need things to be. In total I might need 10 global variables. The VI's themselves are complex and they must be separated, but this is what I'd like to do with regards to global variable usage. My main concern is that my loops run for quite a while so the memory is very 'active'. On the LV website, there is a document that states that, with respect to global variables in a loop, 'labview reclaims the memory after each iteration of the loop.' so do i have much to worry about? Quote Link to comment
Neville D Posted July 27, 2007 Report Share Posted July 27, 2007 QUOTE(sm07 @ Jul 26 2007, 09:40 AM) I have 2 or 3 VI's running in parallel (some may be sub-vi's of others) and i'm wondering how bad is it to use global variables in them. My needs are very simple. For example, in one program i am writing to variable X inside a while loop, and in a second program, I am using variable X to calculate variable Y. Honestly that's as simple as I need things to be. In total I might need 10 global variables. The VI's themselves are complex and they must be separated, but this is what I'd like to do with regards to global variable usage. My main concern is that my loops run for quite a while so the memory is very 'active'. On the LV website, there is a document that states that, with respect to global variables in a loop, 'labview reclaims the memory after each iteration of the loop.' so do i have much to worry about? You could use a Q, where you write data in one of the VI's and read it elsewhere. Q's are very easy to use, and will make sure you don't loose (overwrite) any data that you haven't used in your consumer VI. If you don't care about missing data, then maybe use a notifier. See LV examples for more ideas. If you must use globals, then use a functional global (an unitialized shift register VI with read/write access), as the native LV globals tend to make copies of the data. Neville. Quote Link to comment
Yair Posted July 27, 2007 Report Share Posted July 27, 2007 Unless you're constantly building arrays or concatenating strings in a loop, your memory consumption should probably not be a problem. That is assuming you don't have any very large structures (tens or hundreds of MB). The main reason for not using globals is that it's usually fairly easy to create race conditions which will cause bugs in your code. Other options of transferring data and synchronizing include queues and LV2 style globals. Quote Link to comment
sm07 Posted July 27, 2007 Author Report Share Posted July 27, 2007 QUOTE(yen @ Jul 26 2007, 03:04 PM) Unless you're constantly building arrays or concatenating strings in a loop, your memory consumption should probably not be a problem. That is assuming you don't have any very large structures (tens or hundreds of MB).The main reason for not using globals is that it's usually fairly easy to create race conditions which will cause bugs in your code. Other options of transferring data and synchronizing include queues and http://forums.ni.com/ni/board/message?board.id=170&message.id=240328#M240328' target="_blank">LV2 style globals. All of my data are either individual 'double's or booleans...and there are only about 10 of them in total Quote Link to comment
jzoller Posted July 27, 2007 Report Share Posted July 27, 2007 QUOTE(sm07 @ Jul 26 2007, 02:50 PM) All of my data are either individual 'double's or booleans...and there are only about 10 of them in total If the global is written only in one place, and only read elsewhere, it might be acceptable. The problem with this implementation is that it limits future flexibility in the program, and programs *always* seem to grow. Bite the bullet and use a better structure. You'll learn the pattern for the structure (worthwhile in and of itself!), and never have to worry about what you (or someone else) will do in the code in the future. Joe Z. Quote Link to comment
Topher Posted July 28, 2007 Report Share Posted July 28, 2007 I went global-happy when I started using LabVIEW and regretted it later. It became such a hassle to keep track of them that whenever I would update a program I would start stripping them out. I think I updated the last program that had globals left in it about two weeks ago. It was a lot of work to take them out, but it would have been a lot more work to keep them there and keep them straight. Quote Link to comment
Grampa_of_Oliva_n_Eden Posted July 28, 2007 Report Share Posted July 28, 2007 QUOTE(Topher @ Jul 26 2007, 06:52 PM) I went global-happy when I started using LabVIEW and regretted it later. It became such a hassle to keep track of them that whenever I would update a program I would start stripping them out. I think I updated the last program that had globals left in it about two weeks ago. It was a lot of work to take them out, but it would have been a lot more work to keep them there and keep them straight. Confessions of a global-holic " Hi my name is Ben and I was a global-holic. I used my last global in 1999. My first big project include a super-cluster stored in a global. I learned about excesive data copies and race conditions. I have been global free for about eight years now. " Ben Quote Link to comment
Ton Plomp Posted July 28, 2007 Report Share Posted July 28, 2007 QUOTE(Ben @ Jul 27 2007, 01:20 PM) Hi my name is Ben and I was a global-holic. Welcom Ben! I want to let you know we've all been there and feel what you are going through. Please let me know if you need a sponsor! Ton Quote Link to comment
crelf Posted July 28, 2007 Report Share Posted July 28, 2007 QUOTE(Topher @ Jul 27 2007, 08:52 AM) I went global-happy when I started using LabVIEW and regretted it later. I think almost eveyone has that on their resume Admitting you have a problem is the first step... Quote Link to comment
PaulG. Posted July 28, 2007 Report Share Posted July 28, 2007 QUOTE(Ben @ Jul 27 2007, 07:20 AM) Hi my name is Ben and I was a global-holic. Hi, Ben! Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.