Obtain Queue
- Updated2023-02-17
- 4 minute(s) read
Obtain Queue
Returns a reference to a queue or creates a new reference to a queue.
Use this reference when calling other nodes that perform queue operations.
Inputs/Outputs

max queue size
The maximum number of elements you want the queue to hold.
If a queue with the same name exists, the node ignores this input and uses the maximum queue size from the existing queue.
Default value: -1 — The queue can hold an unlimited number of elements.
Preallocating Memory for Queues
To preallocate memory for a queue, enqueue the number of elements you want to include and then flush the queue. The memory remains allocated for further use of the queue.
What Happens When Maximum Queue Size Is Reached?
If a queue reaches the maximum queue size, the Enqueue Element or Enqueue Element at Opposite End nodes wait until the Dequeue Element or Flush Queue nodes remove elements from the queue.

name
The name of the queue that you want to obtain or create.
Default value: Empty string — Creates an unnamed queue.

element data type
The type of data that you want the queue to contain.
You can wire any data type to this input.

create if not found
A Boolean value that determines whether to create a new queue if one with the same name as name does not exist.
| True | The node creates a queue if one with the same name as name does not exist. |
| False | The node does not create a queue if one with the same name as name does not exist. |
Default value: True

error in
Error conditions that occur before this node runs.
Default value: no error

queue out
A reference to an existing queue or to a new queue created by this node.

created new?
A Boolean value that indicates whether this node created a new queue.
| True | This node created a new queue. |
| False | This node did not create a new queue. |

error out
The node produces this output according to standard error behavior.
This node can return the following error codes.
| 1094 | You tried to obtain an existing queue or notifier reference with the incorrect data type. You can get this error when you obtain a reference to the same queue or notifier but do not wire the same data type as the original specified data type. Unnamed queues and notifiers do not have this restriction, because each request to obtain an unnamed queue or notifier creates a new reference. |
| 1100 | You tried to obtain a queue or notifier that does not exist, so no reference could be returned. You can use the Obtain Queue or Obtain Notifier nodes to look up a queue or notifier by name. This error occurs if create if not found is set to False, and a queue or notifier with the name you specify was not found. |
| 1548 | A queue reference cannot be obtained with a maximum queue size of zero. The max queue size input must either be a positive number or -1 for unlimited size. |
Programming Patterns
Transferring Data Between Loops Using Queue Nodes
Queue Memory Usage
When you enqueue and dequeue elements with resizable data types, such as paths, strings and arrays, you do not affect how much memory the queue uses. Queues transfer data but do not generate copies of the data.
Preventing Unintended Memory Allocation Inside a Loop
When called inside a loop, the Obtain Queue node creates a new reference to the queue each time the loop iterates and memory usage increases because each new reference is an additional few bytes. These bytes are released automatically when the VI stops running. However, in a long-running application, there may appear to be leaking memory as memory usage keeps increasing. To prevent unintended memory allocation, use the Release Queue node in the loop to release the queue reference from memory for each iteration or use Obtain Queue once before the loop begins executing.