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.
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.
09-10-2013 03:34 AM - edited 09-10-2013 03:37 AM
Hello!
I am an student and I am making project that requires me to go beyound 2 loops.
I want to make architecture that will allow to comunicate each loop to each without hard modifications.
I am wondering how to make code clean without queue references wires messing around and going from one loop to another.
- My first Idea was to remove all queue wires and connect to queue by its name like in frame 3:
But Desktop trace execution Toolkit shows that I have memory leak. Documentation says that new queue ref is created when I obtain queue that exists and adresses shows that is true.
-My secound Idea was to use variant atribute and global variable and create functions that will allow me to create, exit , enq and dequeue from whom and whenever I want. Schematic idea looks like this
create
enq
deq
exit
This time I didn't have leaks so may I assume this is correct way?
But people always tell to avoid global variables so I am not sure.
-My third idea was to bundle all queues into cluster and then bundle and unbundle by name whenever I want, There is openG function that allows me to get value from cluster by name so if I name queues it should be easy to do. So I will only have 1 wire for cluster and 1 wire for error for each loop. In this case data flow is keept because all stays with cluster.
-My forth ide was to create functional global to store all queues but it didn;t worked at all 🙂
If someone has done that before please give me a hint 🙂
Best regards
pawhan11
Solved! Go to Solution.
09-10-2013 05:00 AM
Look at the Master/slave pattern (file/new/templates/master...), that's basically how it should be done.
/Y
09-10-2013 05:26 AM
But it is based on notifiers and It only allows to comunicate from master to multiple slaves at the same time...
Or am I looking at wrong example?
09-10-2013 05:33 AM
That sounds like the wrong exaple. 🙂 It should be an event driven producer and a queue-consumer.
Your example ofc has a memory leak since you dont release the queue.
/Y
09-10-2013 06:11 AM
If this is example (only one that has events) you mention I don't know how it relates. Please explain and be patient if You can 🙂
It only allows me to talk from prod to consumer. I can create UE or another queue to talk backwards but thats ont my point. When I have many loops I have many queue wires comming from one loop to another and I want them gone. And Question is how to pass queues qithout wires without making memory leaks.
Best Regards
pawhan11
09-10-2013 06:58 AM
Ah. Hiding wires shouldn't be needed, and the general way of doing it is clumping them up in clusters. In this case we can solve both with an Action Engine.
Create an AE with a cluster of queues, then you need 3 states, Init, Get, Close. (and error in and out)
In init create your queues and store the ref.
Get ofc gets the queues.
Close closes all queues.
Then it should be pretty self explainatory, Init at start of program, Get the queues inside loops, Close all when exiting.
/Y
09-10-2013 10:21 AM
I do this all the time with Action Engine. You will want an Init, Send, and Close case. My suggestion is initialize right before the loop that will do the reading. Pass the queue reference out of the Action Engine to go to the Dequeue Element inside of the loop. I have found it best to have a different Action Engine for each queue. Now another thread can send a message to the reading loop by calling the Send case of the Action Engine. Perform the close once the reading loop is complete.
09-10-2013 11:27 AM
Sounds nice but I will have to create engine to handle 1 queue,
Can I create 1 engine that will handle many queues?
Thanks for this nugget 🙂
Now I am thinking about wiring all queues into cluster like that:
So I can easy dequeue from whom I want and enqueue to who I want
09-10-2013 11:52 AM
@pawhan11 wrote:
Sounds nice but I will have to create engine to handle 1 queue,
Can I create 1 engine that will handle many queues?
You can. My experience says that isn't a good idea. You will have to manage data types, making sure the right queue is written to, and managing the cluster of queue references.
What I did was I made a template for the queue action engine. I have a separate enum type def to manage the cases for the action engine. Every engine you make should use that type def. By making the template, you can quickly make new action engines by simply chaning the data type that is used.
09-11-2013 11:40 AM
Thanks.
It is solved now 🙂