How to Clear SystemVerilog queue

delete all the entries of queue systemverilog

Calling queue.delete() method will delete the complete queue, which leads to deletion of all the entries of queue.

queue delete method

module qu_delete;
  //queue declaration
  int qu[$];  
  
  initial begin

    qu.push_back(2);
    qu.push_back(13);
    qu.push_back(5);
    qu.push_back(65);
    
    $display("[Before-Delete] Queue size is %0d",qu.size());
    qu.delete();
    $display("[After -Delete] Queue size is %0d",qu.size());    
    
  end
endmodule

Simulator Output

[Before-Delete] Queue size is 4
[After -Delete] Queue size is 0

Click to execute on