quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Dynamic Extension

A dynamic extension is used when auxiliary data needs to be associated with the data object, such as a constraint or a callback function pointer. This is accomplished via the scv_smart_ptr template in the Verification Standard. For example, the following code generates a random value for an integer and register a callback.

   

space.gif

The scv_shared_ptr template enables sharing of data objects among multiple C++ threads by performing automatic memory management. The scv_smart_ptr template combines scv_shared_ptr and scv_extensions to attach auxiliary data to a data object. The scv_smart_ptr subsumes the functionality in scv_shared_ptr, but scv_smart_ptr is more costly in both memory space and performance, so it should be used only when dynamic extensions are needed.

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example : scv_smart_ptr
   

space.gif


  1 #include <scv.h>
  2 
  3 class packet_t {
  4   public : 
  5     sc_uint<8>  addr;
  6     sc_uint<12> data;
  7 };
  8 
  9 SCV_EXTENSIONS(packet_t) {
 10   public:
 11     scv_extensions< sc_uint<8> > addr;
 12     scv_extensions< sc_uint<12> > data;
 13     SCV_EXTENSIONS_CTOR(packet_t) {
 14       SCV_FIELD(addr);
 15       SCV_FIELD(data);
 16     }
 17 };
 18 
 19 void do_something (scv_smart_ptr<packet_t> p) {
 20   cout << "address : " << p->addr << endl;
 21   cout << "data : " << p->data << endl;
 22   if (p->data == 0) {
 23     p-> data = rand();
 24   }
 25   if (p-> addr == 0) {
 26     p-> addr = rand();
 27   }
 28   cout << "The whole packet : " << endl;
 29   p->print();
 30 };
 31 
 32 int sc_main (int argc, char* argv[]) {
 33   scv_smart_ptr<packet_t> pkt_p("packet");
 34   do_something(pkt_p);
 35   return 0;
 36 }
You could download file scv_smart_ptr.cpp here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation Output : scv_smart_ptr
   

space.gif

 address : 0
 data : 0
 The whole packet : 
 {
   addr:54
   data:502
 }
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com