# Problem with the associative array with queue (not taking data corrrectly)

**URL:** <https://verificationacademy.com/forums/t/problem-with-the-associative-array-with-queue-not-taking-data-corrrectly/37019>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, Queues, Learning-System-Verilog, associative-array\
**Created:** [January 13, 2020, 1:28pm UTC](https://verificationacademy.com/forums/t/problem-with-the-associative-array-with-queue-not-taking-data-corrrectly/37019 "2020-01-13T13:28:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahulraoece](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/71e660/32.png) [@rahulraoece](https://verificationacademy.com/forums/u/rahulraoece)\
**Post date:** [January 13, 2020, 1:28pm UTC](https://verificationacademy.com/forums/t/problem-with-the-associative-array-with-queue-not-taking-data-corrrectly/37019/1 "2020-01-13T13:28:18Z")

</div>

as i am randomizing handle for 5 times 5 different address are generated but when displaying the queue it is printing the same address value genetared at that transaction.push back is not working …

```verilog
class demo;
  rand bit[3:0] addr;
  bit [2:0] index=2;
endclass
class memory;
  demo mem[int][$];
endclass
module top;
   memory mem_h;
  
  demo d1,d2;
  initial begin 
      mem_h= new();
     d1=new();
    d2=new();
    repeat(5)
      begin 
        assert (d2.randomize());
        mem_h.mem[d1.index].push_back(d2);
        $display("value of q=%p,mem_address =%d",mem_h.mem,mem_h);
      end
  end
endmodule

```

output

```auto
value of q='{2:'{'{addr:2, index:2}}},mem_address = 139819985821116
# KERNEL: value of q='{2:'{'{addr:5, index:2}, '{addr:5, index:2}}},mem_address = 139819985821116
# KERNEL: value of q='{2:'{'{addr:10, index:2}, '{addr:10, index:2}, '{addr:10, index:2}}},mem_address = 139819985821116
# KERNEL: value of q='{2:'{'{addr:4, index:2}, '{addr:4, index:2}, '{addr:4, index:2}, '{addr:4, index:2}}},mem_address = 139819985821116
# KERNEL: value of q='{2:'{'{addr:2, index:2}, '{addr:2, index:2}, '{addr:2, index:2}, '{addr:2, index:2}, '{addr:2, index:2}}},mem_address =

```

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [January 13, 2020, 2:59pm UTC](https://verificationacademy.com/forums/t/problem-with-the-associative-array-with-queue-not-taking-data-corrrectly/37019/2 "2020-01-13T14:59:13Z")

</div>

_In reply to [rahulraoece](https://verificationacademy.com/forums/t/problem-with-the-associative-array-with-queue-not-taking-data-corrrectly/37019):_  
Please use [code tags](https://verificationacademy.com/forums/announcements/please-format-your-code-code-and/code-tags) making your code easier to read. I have added them for you.

You are pushing the same handle (d2) to the queue, so all queue entries have the same value. You need to move the construction of d2 into the loop.

```verilog
initial begin 
    mem_h= new();
    d1=new();
    repeat(5)
      begin 
        d2=new();
        assert (d2.randomize());
        mem_h.mem[d1.index].push_back(d2);
        $display("value of q=%p,mem_address =%d",mem_h.mem,mem_h);
      end
  end

```

---

<div class="post-metadata">

**Author:** ![rahulraoece](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/71e660/32.png) [@rahulraoece](https://verificationacademy.com/forums/u/rahulraoece)\
**Post date:** [January 13, 2020, 4:20pm UTC](https://verificationacademy.com/forums/t/problem-with-the-associative-array-with-queue-not-taking-data-corrrectly/37019/3 "2020-01-13T16:20:27Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/problem-with-the-associative-array-with-queue-not-taking-data-corrrectly/37019/2):_

> _In reply to [rahulraoece](https://verificationacademy.com/forums/t/problem-with-the-associative-array-with-queue-not-taking-data-corrrectly/37019/2):_  
> Please use [code tags](https://verificationacademy.com/forums/announcements/please-format-your-code-code-and/code-tags) making your code easier to read. I have added them for you.  
> You are pushing the same handle (d2) to the queue, so all queue entries have the same value. You need to move the construction of d2 into the loop.

```verilog
initial begin 
mem_h= new();
d1=new();
repeat(5)
begin 
d2=new();
assert (d2.randomize());
mem_h.mem[d1.index].push_back(d2);
$display("value of q=%p,mem_address =%d",mem_h.mem,mem_h);
end
end

```

its working ,thank you…
