Cranes Varsity Blog

A Copy constructor is an overloaded constructor used to declare and initialize an object from another object.

Copy Constructor is of two types:

Syntax Of User-defined Copy Constructor:

Class_name(const class_name &old_object);

When Copy Constructor is called

Copy Constructor is called in the following scenarios:

  • When we initialize the object with another existing object of the same class type. For example, Student s1 = s2, where Student is the class.
  • When the object of the same class type is passed by value as an argument.
  • When the function returns the object of the same class type by value.

Two types of copies are produced by the constructor:

  • Shallow copy
  • Deep copy

Shallow Copy

  • The default copy constructor can only produce the shallow copy.
  • A Shallow copy is defined as the process of creating the copy of an object by copying data of all the member variables as it is.

    #include <iostream> 

    using namespace std; 

     class Demo 

    { 

        int a; 

        int b; 

        int *p; 

        public: 

        Demo() 

        { 

            p=new int; 

        } 

        void setdata(int x,int y,int z) 

        { 

            a=x; 

            b=y; 

            *p=z; 

        } 

        void showdata() 

        { 

            std::cout << "value of a is : " <<a<< std::endl; 

            std::cout << "value of b is : " <<b<< std::endl; 

            std::cout << "value of *p is : " <<*p<< std::endl; 

        } 

    }; 

    int main() 

    { 

      Demo d1; 

      d1.setdata(4,5,7); 

      Demo d2 = d1; 

      d2.showdata(); 

        return 0; 

    } 

Demo d2 = d1; calls the default constructor defined by the compiler. The default constructor creates the exact copy or shallow copy of the existing object. Thus, the pointer p of both the objects point to the same memory location. Therefore, when the memory of a field is freed, the memory of another field is also automatically freed as both the fields point to the same memory location. This problem is solved by the user-defined constructor that creates the Deep copy.

Deep copy

Deep copy dynamically allocates the memory for the copy and then copies the actual value, both the source and copy have distinct memory locations. In this way, both the source and copy are distinct and will not share the same memory location. Deep copy requires us to write the user-defined constructor.

    #include <iostream> 

    using namespace std; 

    class Demo 

    { 

        public: 

        int a; 

        int b; 

        int *p; 

     

        Demo() 

        { 

            p=new int; 

        } 

        Demo(Demo &d) 

        { 

            a = d.a; 

            b = d.b; 

            p = new int; 

            *p = *(d.p); 

        } 

        void setdata(int x,int y,int z) 

        { 

            a=x; 

            b=y; 

            *p=z; 

        } 

        void showdata() 

        { 

            std::cout << "value of a is : " <<a<< std::endl; 

            std::cout << "value of b is : " <<b<< std::endl; 

            std::cout << "value of *p is : " <<*p<< std::endl; 

        } 

    }; 

    int main() 

    { 

      Demo d1; 

      d1.setdata(4,5,7); 

      Demo d2 = d1; 

      d2.showdata(); 

      return 0; 

    } 

Demo d2 = d1; calls the copy constructor defined by the user. It creates the exact copy of the value types data and the object pointed by the pointer p. Deep copy does not create the copy of a reference type variable.

The present VLSI electronic systems rely on the Silicon MOS (metal oxide semiconductor) technology whose advances will soon come to saturation. Carbon nanotubes represent advancement in the materials technology with potential for providing switching devices that may be faster and smaller than the present MOS devices. Carbon nanotubes are miniature tube structures with intriguing characteristics. The tube, in the normal untwisted state, conducts electricity. When twisted, the tube acts as a semiconductor.

 This transistor is considered one of the greatest inventions of the twentieth century. It has helped to bring about both the information and computing age. One reason for success is its ability to decrease in size and increase in speed. This property is summarized in Moore’s law. It states that the transistor’s size will decrease exponentially while its speed will increase exponentially. Moore’s law has allowed the technology sector to progress and remain competitive.

The physical barriers arise due to the continued shrinking of the current transistor used today, the Metal-Oxide Field Effect Transistor or MOSFET. As the size shrinks, the thickness of the insulators, which are used to electronically isolate parts of the transistor, reduces. With the thinner insulation, the carriers are able to quantum-mechanically tunnel across the insulation. The result is a short circuit allowing current to flow directly from source to drain, drain to the body, and even through the thin gate oxide, that separates the gate from the channel. In addition, doping becomes a problem since it relies on percentages. If the total amount of atoms gets very small then a fractional dopant atom might be required, which of course is impossible to. In addition, economic problems arise from producing and maintaining the fabrication lines. One proposed solution is the use of carbon nanotubes instead of silicon to make the transistors.

The construction and operation of CNFET is similar to the MOSFETs that we use today, thus giving them name Carbon Nanotube Field-Effect Transistor, or CNFET. Three of the most important characteristics of any transistor are speed, scalability, and power

  • SPEED- The carbon nanotubes unique one-dimensional nature; it is able to utilize ballistic transport. Ballistic transport means that the mean free path is longer than the path. Thus, the charge carriers do not collide, reducing resistance to negligible levels. The result is a capability to achieve speeds of Terahertz or more, compared to today’s processors that operate at 3 gigahertz.
  • SCALABILITY- A group in IBM discovered an interesting property of the CNFETs scalability. While the CNFETs improve with scaling, it is not conventional. They seem to follow the behavior of Schottky barrier MOSFETs, instead of regular MOSFETs. For this reason, the group at IBM feels that the CNFETs limits for scaling are unclear. However, they do note that, in a structured array, the CNFETs will produce enough gain and fan out for real life applications. In addition, despite the CNFETs murky limits of scaling, it still will outperform silicon MOSFETs limits of scaling.
  • POWER- The same group at IBM compared some properties of the CNFET to both a high performance silicon MOSFET and a newer MOSFET design that utilize Silicon On-Insulator (SOI) technology,the results are displayed in table 1.

 

Table 1: Comparison between MOSFET and CNT

Circuit

FET

Delay (in pico second)

Power (in micro watt)

Inverter

CMOS

16.58

9.81

CNT

3.78

0.25

2 Input NAND

CMOS

24.32

20.67

CNT

5.98

0.69

2 Input NOR

CMOS

39.26

22.13

CNT

6.49

0.48

 

One important difference is in I(OFF). The CNTFET has a drop of about 70% as compared to the conventional MOSFET. This means that the power being wasted while the transistor is off is greatly reduced. In addition, we notice that I(ON), or drive current, is larger than both technologies. In fact, it is three to four times larger. Normally we would think that this would be a bad thing since our first instinct would mean higher power consumption. However, since the nanotube has ballistic conductance, it actually has a smaller resistance. Thus, the power consumption is the same if not smaller than the current MOSFET design. This is also supported by the two to four times increase in trans-conductance. The real big surprise is that the CNTFET is able to outperform both the current and newer technologies, despite the large gate length and gate oxide thickness. So naturally, when the CNFET design is optimized, the CNTFET will surely outperform the current technology. For these reasons, the CNTFET is a very strong contender to replace the current technology.

At the present time cars and other private vehicles are used daily by many peoples. The biggest problem regarding the increased use of private transport is the increasing number of fatalities that occur due to accidents on the roads; the expense and related dangers have been recognized as a serious problem being confronted by modern society. VANET provides a wireless communication between moving vehicles, using a dedicated short range communication (DSRC). DSRC is essentially IEEE 802.11a amended for low overhead operation to 802.11p; the IEEE then standardizes the whole communication stack by the 1609 family of standards referring to wireless access in vehicular environments (WAVE). Vehicle can communicate with other vehicles directly forming vehicle to vehicle communication (V2V) or communicate with fixed equipment next to the road, referred to as road side unit (RSU) forming vehicle to infrastructure communication (V2I)

These types of communications allow vehicles to share different kinds of information, for example, safety information for the purpose of accident prevention, post-accident investigation or traffic jams. Other type of information can be disseminated such as traveler related information which is considered as non-safety information. The intention behind distributing and sharing this information is to provide a safety message to warn drivers about expected hazards in order to decrease the number of accidents and save people's lives, or to provide passengers with pleasant journeys.

VANET architecture

The communication between vehicles or between a vehicle and an RSU is achieved through a wireless medium called WAVE. This method of communication provides a wide range of information to drivers and travelers and enables safety applications to enhance road safety and provide a comfortable driving. The main system components are the application unit (AU), OBU and RSU. Typically the RSU hosts an application that provides services and the OBU is a peer device that uses the services provided. The application may reside in the RSU or in the OBU; the device that hosts the application is called the provider and the device using the application is described as the user. Each vehicle is equipped with an OBU and a set of sensors to collect and process the information then send it on as a message to other vehicles or RSUs through the wireless medium; it also carries a single or multiple AU that use the applications provided by the provider using OBU connection capabilities. The RSU can also connect to the Internet or to another server which allows AU's from multiple vehicles to connect to the Internet

On Board unit (OBU)

An OBU is a wave device usually mounted on-board a vehicle used for exchanging information with RSUs or with other OBUs. It consists of a resource command processor (RCP), and resources include a read/write memory used to store and retrieve information, a user interface, a specialized interface to connect to other OBUs and a network device for short range wireless communication based on IEEE 802.11p radio technology. It may additionally include another network device for non-safety applications based on other radio technologies such as IEEE 802.11a/b/g/n. The OBU connects to the RSU or to other OBUs through a wireless link based on the IEEE 802.11p radio frequency channel, and is responsible for the communications with other OBUs or with RSUs; it also provides a communication services to the AU and forwards data on behalf of other OBUs on the network. The main functions of the OBU are wireless radio access, ad hoc and geographical routing, network congestion control, reliable message transfer, data security and IP mobility.

Application unit (AU)

The AU is the device equipped within the vehicle that uses the applications provided by the provider using the communication capabilities of the OBU. The AU can be a dedicated device for safety applications or a normal device such as a personal digital assistant (PDA) to run the Internet, the AU can be connected to the OBU through a wired or wireless connection and may reside with the OBU in a single physical unit; the distinction between the AU and the OBU is logical. The AU communicates with the network solely via the OBU which takes responsibility for all mobility and networking functions

Roadside unit (RSU)

The RSU is a wave device usually fixed along the road side or in dedicated locations such as at junctions or near parking spaces. The RSU is equipped with one network device for a dedicated short range communication based on IEEE 802.11p radio technology, and can also be equipped with other network devices so as to be used for the purpose of communication within the infrastructural network

Bootstrapping in computer science is the technique for producing a self-compiling compiler. That is, compiler / assembler written in the source programming language that it intends to compile. An initial core version of the compiler is generated in a different language mostly assembly language. Successive developed versions of the compiler are developed using this minimal subset of the language.

When a computer is turned on, it is booted up with the code that is stored in ROM. The same code tries to figure out how much to load and start your kernel. The kernel verifies all the system’s hardware, and initializes the system’s init process, which is always PID 1. A lot of things will happen before a login prompt can appear for the user to login. File systems must be checked and mounted, and the system daemons started. These procedures are managed by a series of shell scripts that are run in sequence in init. The above entire process is called as Booting process.

There are two ways where a UNIX / LINUX OS can boot, ‘Automatic mode’ & ‘Manual mode’

Without any external assistance if the system performs the whole boot procedure, then it is called ‘Automatic Mode’. In ‘manual mode’, at first system follows the automatic procedure up to a point before most initialization scripts have been run, And then turns control over to an operator. Up to this point computer will be running in ‘Single User mode’, Most of the system process will not be running, while other users cannot login as well.

Steps Involved in Boot process:

It is involved in six different steps:

  1. Loading the code and initializing the kernel
  2. Detecting the Devices and configuring them
  3. Creating spontaneous system processes
  4. Operator intervention (manual boot only)
  5. Execution of system startup scripts
  6. Multiuser operation

 

Variable length argument is feature that allows a function to receive any number of arguments. These are situations where we want a function to handle variable number of arguments according to requirements.

  1. Sum of given numbers.
  2. Minimum of given numbers.

Variable number of arguments are represented by three dotes ( . . .  )

int Fun(int num, . . .)

{

…….

…….

}

int main()

{

            Fun(2,10,20);

            Fun(3,5,6,7);

}

In the above function, when we calling the function the first argument will be always an int  ,it will represent no .of arguments that we are passing in function call. In definition the first formal parameter will access the total no .of argument and followed with three dots( . . ).i.e,ellipses.  To use this functionality always we need to include stdarg.h header file which provides the functions and macros to implement the functionality variable no .of arguments and follow the given steps:

  • Define a function with its last parameter as ellipses and the one just before the ellipses is always an int which will represent the number of arguments.
  • Create ava_list type variable in the function definition. This type is defined in stdarg.h header file.
  • Use int parameter and va_start macro to initialize the va_list variable to an argument list. The macro va_start is defined in stdarg.h header file.
  • Use va_arg macro and va_list variable to access each item in argument list.
  • Use a macro va_end to clean up the memory assigned to va_list 

Now let us follow the above steps and write down a simple function which can take the variable number of parameters and return their average.

#include<stdio.h>

#include<stdarg.h>

float fun(int num , …)

{

            int i=0;

            float sum=0;

            //creating a va_list type variable

            va_list valist;

            //initialize valist fom num number of arguments

            va_start (valist , num);

            //access all the arguments assigned to valist

            for(;i<num;i++)

                        sum= sum + va_arg(valist,int);

            //cleanup memory reserved for valist

            va_end(valist);

            return sum/num;

}

int main()

{

            printf(“the average of 2,3,4 is = %f\n”, fun(3,2,3,4));

            printf(“the average of 10,20,30,40 is = %f\n”, fun(4,10,20,30,40));

}