Related objects of classes because of mailbox sending

hi all!
i have a class T, which containes random variables. i randomize it in class A, and then send it to classes B and C via mailboxes, like this:
Class A;
T t;

task run();
t = new();
assert(t.randomize);
mbx_A_B.put(t);
mbx_A_C.put(t);
endtask

endclass

Class B;
T t;

task run();
mbx_A_B.get(t);
//other code
endtask

endclass

But if i change in class B variable, located in object t (class T) after receiving it, it automatically changes in C too. So i don’t really “send” it from one object to another, but only make a reference to it, am i right? and if i do, how can i avoid this?

You are correct in that a mailbox will pass by reference. In order to prevent mutual interference, you should create a clone of the object prior to placing it in the mailbox.

Thank you for your reply :)
But how do i do that? Do you mean, i have to write something like this:

Class B;
T t;
T t_clone;//a clone of the object

task run();
mbx_A_B.get(t);
t_clone = new();//create object
t_clone = t;//copy
//other code
endtask
endclass

Or should it be something more tricky?:)

Ok, i figured it out:) it’s all explained here: WWW.TESTBENCH.IN - Systemverilog OOPS
again, thank you for your post!

The example that you are looking at isn’t very complete in that the copy() function will only create a new sub-class and not actually copy the values as you desire.

Take a look at the UVM Transaction Methods page to get a better understanding of a copy function. While this is for a uvm_object, the concepts are the same.