Object Copying Techniques in SystemVerilog, Cheat Sheet of Computer science

Object copying techniques in systemverilog, covering copy by handle, shallow copy, and deep copy. It details the memory usage, object independence, and performance implications of each method. The document also provides code examples and a comparison table to highlight the advantages and disadvantages of each copying technique, making it a useful resource for understanding object-oriented programming concepts in systemverilog. It is useful for understanding object-oriented programming concepts in systemverilog. (410 characters)

Typology: Cheat Sheet

2025/2026

Uploaded on 09/19/2025

sdf-sdf-39
sdf-sdf-39 🇮🇳

1 document

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Copying methods in SV
Un d e r st a n d i n g O bj ec t Co py Te ch ni qu e s & T he ir I mp a c t
By : R is hi ta J os hi , D h r uv il S h a h , H et v i S ha h, P us t i S h a h & M i s h a S h a r ma
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Object Copying Techniques in SystemVerilog and more Cheat Sheet Computer science in PDF only on Docsity!

Copying methods in SV

Un d e r s t a n d i n g O b j e c t C o p y T e c h n i q u e s & T h e i r I mp a c t

B y : R i s h i t a J o s h i , D h r u v i l S h a h , H e t v i S h a h , P u s t i S h a h & M i s h a S h a r m a

Introduction

  • (^) SystemVerilog supports Object-Oriented Programming.
  • (^) Objects are manipulated using handles.
  • (^) What is an Object? An object in SystemVerilog is an instance of a class that contains data (properties) and functions (methods).
  • (^) What is a Handle? A handle is like a pointer that references the memory location of an object, allowing access to that object's members.

3 methods to copy objects :

  • (^) Copy by Handle : 1 memory, 2 handles (same object)
  • (^) Shallow Copy : 2 objects, primitive copied, references shared
  • (^) Deep Copy : fully independent objects, including nested data

Copy by Handle :

  • (^) Only the object handle is copied.
  • (^) Both variables refer to the same object in memory. class packet; int id; endclass module copy_by_handle; initial begin packet p1; packet p2; p1 = new(); p1.id = 1; p2 = p1; $display("BEFORE CHANGING P2 :\np1.id = %0d \np2.id = %0d", p1.id, p2.id); p2.id = 2; $display("AFTER CHANGING P2 :\np1.id = %0d \np2.id = %0d", p1.id, p2.id); end endmodule Output :

Deep Copy :

  • (^) A complete clone is created.
  • (^) All referenced objects are duplicated. class packet; int id; //declaration of properties int data; function packet deep_copy(); //declaration of method packet pc = new(); pc.id = this.id; pc.data = this.data; return pc; endfunction endclass module deep_copy; packet p1, p2; // object declaration initial begin p1 = new(); p1.id = 1; p1.data = 123; p2 = p1.deep_copy(); $display("BEFORE CHANGING P2 :\np1.id = %0d, p1.data = %0d \np2.id = %0d, p2.data = %0d", p1.id, p1.data, p2.id, p2.data); p2.id = 2; p2.data = 456; $display("AFTER CHANGING P2 :\np1.id = %0d, p1.data = %0d \np2.id = %0d, p2.data = %0d", p1.id, p1.data, p2.id, p2.data); Output :

Comparision : Feature Copy by Handle Shallow Copy Deep Copy Object memory Shared Separate Separate Nested Object Copy? Shared Shared Cloned Safe from overwrite? No No Yes Performance Fast Medium Slower

Advantages of Shallow Copy :

  • (^) Creates a separate outer object, allowing partial independence.
  • (^) More efficient than deep copy in terms of speed and memory.
  • (^) Useful when inner references don’t need to be isolated.

Advantages of Deep Copy :

  • (^) Complete independence from the original object.
  • (^) Prevents side effects caused by shared references.
  • (^) Safer for preserving state across simulations.
  • (^) Only required properties can be copied.