12-31-2024 01:46 PM
Are named notifiers and queues better than wired. Specifically, in LabVIEW 2023.
Named: Using an obtain notifier for each loop in an app that uses the notifier, passing each obtain notifier the same name. No wires to pass the notifier Refnum between loops and the obtain notifier is outside of the loop so it gets called once per loop.
Wired: Use one obtain notifier for all of the loops with a wire passing the one Refnum to each loop.
Could named notifiers work slower than wired notifiers?
Could there be an architectural reason to choose wired over named notifiers?
12-31-2024 01:57 PM
I had always assumed that if you didn't provide a name, it just kept it blank, but won't let you search for a blank notifier.
I had also assumed, if you stored the actual notifier (in let's say private memory in a class, etc), rather than the name, it might save the slight overhead of the string comparison (that is to say, you don't have to 'find it').
I too am curious how this works under the hood.
12-31-2024 02:11 PM - edited 12-31-2024 02:12 PM
You may be doing something similar (can't tell for sure from the post)...
Also, this has become my favorite way to kill multiple loops in different parts of a program. It's an abuse of the language that makes me smile each time I use it.
I create a notifier "kill loops" in an init
Then i wire my get notifier's status' error terminal into the stop of a while loop (when I feel especially clever I only stop it when i get an error 1100).
As long as the notifier exists, we are good to keep looping. As soon as it get deallocated, it throws an error and the loop stops.
When I want t stop it, i just release the notifier to deallocate it from anywhere in the program, and it will throw an error 1100 in each loop, which i cue as the stop signal.
Granted, this is just basically a named global.. with all the pitfalls of a global... but heck, all data is global, if you try hard enough. There are probably plenty of way better ways, (FGV, classes, globals, singleton classes, etc)... but this one makes me smile...
12-31-2024 02:20 PM - edited 12-31-2024 02:21 PM
I couldn't tell from your post, but you may be up to something similar to the below. This has become my favorite way of stopping multiple loops in various VIs in different locations. It is an abuse of the language that makes me smile.
I create a notifer, called "kill loops" or something similar in an init method/VI.
Then I feed the error terminal of a get notifier status into the stop terminal.
As long as the notifier exists, the loop will continue. When it gets released, it'll throw an error 1100 and the loop will stop (the slightly better way would be to compare the error code to 1100 and only stop when the error code is equal to 1100).
When I want the loops to stop, i just release the notifier from anywhere in the program.
Granted, this is only a glorified named global when you think about how I'm using/abusing it.. but heck, all data's global if you try hard enough. There are many other/better ways (classes, FGVs, traditional notifiers, singleton classes, etc) to do this, but this way always makes me smile.
12-31-2024 03:02 PM
A named Queue or Notifier becomes global data. I much prefer not to have global data, unless it is extremely carefully maintained, as it is easy to abuse and break.
Under the hood, if you obtain a named queue/notifier, it does a lookup for that name and returns a reference for that queue/notifier. This does cause an increment in the "obtain count" for that queue/notifier. When you release a queue/notifier, it clears that immediate reference and decrements the count. If the count is 0, the queue/notifier is destroyed (releases all memory of it).
When it comes to queues, I make sure the consumer (the loop the dequeues from it) is in full control of the lifetime of that queue. It creates the queue and passes it to whoever needs it via a multitude of methods. It then destroys the queue when it is complete.
12-31-2024 11:22 PM
If I can, I avoid naming queues. Yes, I have to pass the reference to whoever needs it, but I don't have to worry about accidentally using the same name in some other VI that I make 3 months later and chase my tail debugging some weird behavior where these two different VIs are playing games with the same queue.
to be fair, this has never happened to me ever, but it's possible, and so I just don't name them unless I have a very good reason to and even then I give them a very specific name (eg. NOT "commands" or some such) so that there's minimal chance me or anyone else happens to use the same name somewhere else in the app instance
01-02-2025 09:12 AM
The few times I use named ques (agree that they should be avoided), I try to add some salt characters to the name to avoid the chance that another programmer (or myself) will accidently re-use my que's/notifier's name. For example:
"Master Shutdown - 452043524523452345"
I also often make a vi that just returns the constant name of the que/notifier (if performance is an issue, in-line it). Just makes it easier to manage, for me.
Agree with crossrulz that once you give 'em a name, they are basically globals (with all the baggage that comes with globals). Passing the reference around is almost always the more safe/elegant solution.