Wednesday, July 21, 2021

Inline function with example

C++ inline function is powerful concept that is commonly used with classes. If a function is inline, the compiler places a copy of the code of that function at each point where the function is called at compile time.

Any change to an inline function could require all clients of the function to be recompiled because compiler would need to replace all the code once again otherwise it will continue with old functionality.

To inline a function, place the keyword inline before the function name and define the function before any calls are made to the function. The compiler can ignore the inline qualifier in case defined function is more than a line.

A function definition in a class definition is an inline function definition, even without the use of the inline specifier.

Following is an example, which makes use of inline function to return max of two numbers −

#include <iostream>
 
using namespace std;

inline int Max(int x, int y) {
   return (x > y)? x : y;
}

// Main function for the program
int main() {
   cout << "Max (20,10): " << Max(20,10) << endl;
   cout << "Max (0,200): " << Max(0,200) << endl;
   cout << "Max (100,1010): " << Max(100,1010) << endl;
   
   return 0;
}

When the above code is compiled and executed, it produces the following result −

Max (20,10): 20
Max (0,200): 200
Max (100,1010): 1010

Tuesday, July 20, 2021

Definition of 'Computer Virus ?

Definition: A computer virus is a malicious software program loaded onto a user’s computer without the user’s knowledge and performs malicious actions.

Description: The term 'computer virus' was first formally defined by Fred Cohen in 1983. Computer viruses never occur naturally. They are always induced by people. Once created and released, however, their diffusion is not directly under human control. After entering a computer, a virus attaches itself to another program in such a way that execution of the host program triggers the action of the virus simultaneously. It can self-replicate, inserting itself onto other programs or files, infecting them in the process. Not all computer viruses are destructive though. However, most of them perform actions that are malicious in nature, such as destroying data. Some viruses wreak havoc as soon as their code is executed, while others lie dormant until a particular event (as programmed) gets initiated, that causes their code to run in the computer. Viruses spread when the software or documents they get attached to are transferred from one computer to another using a network, a disk, file sharing methods, or through infected e-mail attachments. Some viruses use different stealth strategies to avoid their detection from anti-virus software. For example, some can infect files without increasing their sizes, while others try to evade detection by killing the tasks associated with the antivirus software before they can be detected. Some old viruses make sure that the "last modified" date of a host file stays the same when they infect the file.

What is the difference between numbered list and bulleted list in ms word ?

In bulleted lists, each paragraph begins with a bullet character. In numbered lists, each paragraph begins with an expression that includes a number or letter and a separator such as a period or parenthesis. The numbers in a numbered list are updated automatically when you add or remove paragraphs in the list.

Eg:

  • These
  • are
  • bullets

In a numbered list this is replaced by a number, in sequential order.

Eg:

1. This

2. Himmat


Query in MS Access

query is a request for data results, and for action on data. You can use a query to answer a simple question, to perform calculations, to combine data from different tables, or even to add, change, or delete table data.

  • As tables grow in size they can have hundreds of thousands of records, which makes it impossible for the user to pick out specific records from that table.

  • With a query you can apply a filter to the table's data, so that you only get the information that you want.

  • Queries that you use to retrieve data from a table or to make calculations are called select queries.

  • Queries that add, change, or delete data are called action queries.

  • You can also use a query to supply data for a form or report.

  • In a well-designed database, the data that you want to present by using a form or report is often located in several different tables.

  • The tricky part of queries is that you must understand how to construct one before you can actually use them.

Create Select Query

If you want to review data from only certain fields in a table, or review data from multiple tables simultaneously or maybe just see the databased on certain criteria, you can use the Select query. Let us now look into a simple example in which we will create a simple query which will retrieve information from tblEmployees table. Open the database and click on the Create tab.

how to put comments in xml

This chapter explains how comments work in XML documents. XML comments are similar to HTML comments. The comments are added as notes or lines for understanding the purpose of an XML code.

Comments can be used to include related links, information, and terms. They are visible only in the source code; not in the XML code. Comments may appear anywhere in XML code.

Syntax
XML comment has the following syntax −

<!--Your comment-->
A comment starts with <!-- and ends with -->. You can add textual notes as comments between the characters. You must not nest one comment inside the other.

Example
Following example demonstrates the use of comments in XML document −

<?xml version = "1.0" encoding = "UTF-8" ?>
<!--Students grades are uploaded by months-->
<class_list>
   <student>
      <name> RATHORE </name>
      <grade>A</grade>
   </student>
</class_list>
Any text between <!-- and --> characters is considered as a comment.

XML Comments Rules
Following rules should be followed for XML comments −

Comments cannot appear before XML declaration.
Comments may appear anywhere in a document.
Comments must not appear within attribute values.
Comments cannot be nested inside the other comments.

Friday, July 16, 2021

Different Types of ROM

 Different Types of ROM

The different types of ROMs will also help you understand how they’re used for different applications, and which type may apply to your application.

The different types of ROM used in the industry are:

  1. PROM (Programmable ROM)
  2. EPROM (Erasable Programmable ROM)
  3. EEPROM (electrically erasable programmable ROM)
  4. Flash EPROM
  5. Mask ROM

1. PROM (programmable ROM) and OTP

PROM refers to the kind of ROM that the user can burn information into. In other words, PROM is a user-programmable memory.

Bipolar PROM IC
Bipolar PROM IC

For every bit of the PROM, there exists a fuse. PROM is programmed by blowing the fuses. If the information burned into PROM is wrong, that PROM must be discarded since its internal fuses are blown permanently. For this reason, PROM is also referred to as OTP (One Time Programmable).

Programming ROM also called burning ROM, requires special equipment called a ROM burner or ROM programmer.

2. EPROM (erasable programmable ROM) and UV-EPROM

EPROM was invented to allow making changes in the contents of PROM after it is burned.

In EPROM, one can program the memory chip and erase it thousands of times. This is especially necessary during the development of the prototype of a microprocessor-based project.

CMOS UV-EPROM IC
CMOS UV-EPROM IC

A widely used EPROM is called UV-EPROM, where UV stands for ultraviolet. The only problem with UV-EPROM is that erasing its contents can take up to 20 minutes.

All UV-EPROM chips have a window through which the programmer can shine ultraviolet (UV) radiation to erase the chip’s contents. For this reason, EPROM is also referred to as UV-erasable EPROM or simply UV-EPROM.

Programming a UV-EPROM

To program a UV-EPROM chip, the following steps must be taken:

  1. Its contents must be erased. To erase a chip, remove it from its socket on the system board and place it in EPROM erasure equipment to expose it to UV radiation for 5-20 minutes.
  2. Program the chip. To program a UV-EPROM chip, place it in the ROM burner (programmer). To burn code or data into EPROM, the ROM burner uses 12.5 volts or higher, depending on the EPROM type. This voltage is referred to as Vpp in the UV-EPROM datasheet.
  3. Place the chip back into its socket on the system board.

As can be seen from the above steps, not only is there an EPROM programmer (burner), but there is also separate EPROM erasure equipment.

The main problem, and indeed the major disadvantage of UV-EPROM, is that it cannot be erased and programmed while it is in the system board. To provide a solution to this problem, EEPROM was invented.

3. EEPROM (electrically erasable programmable ROM)

EEPROM has several advantages over EPROM, such as the fact that its method of erasure is electrical and therefore instant as opposed to the 20-minute erasure time required for UV-EPROM.

ATMEL Parallel EEPROM
ATMEL Parallel EEPROM

In addition, in EEPROM one can select which byte to be erased, in contrast to UV-EPROM, in which the entire contents of ROM are erased.

However, the main advantage of EEPROM is that one can program and erase its contents while it is still in the system board. It does not require the physical removal of the memory chip from its socket. In other words, unlike UV-EPROM, EEPROM does not require an external erasure and programming device.

To utilize EEPROM fully, the designer must incorporate the circuitry to program the EEPROM into the system board. In general, the cost per bit for EEPROM is much higher than for UV-EPROM.

4. Flash Memory EPROM

Since the early 1990s, Flash EPROM has become a popular user-programmable memory chip. and for good reasons. 

  1. First, the erasure of the entire contents takes less than a second, or one might say in a flash, hence its name, Flash memory.
  2. In addition, the erasure method is electrical, and for this reason, it is sometimes referred to as Flash EEPROM. To avoid confusion, it is commonly called Flash memory.
flash memory eprom
Flash memory EPROM

The major difference between EEPROM and Flash memory is that when Flash memory’s contents are erased, the entire device is erased, in contrast to EEPROM, where one can erase the desired byte.

Although in many Flash memories recently made available the contents are divided into blocks and the erasure can be done block by block, unlike EEPROM, Flash memory has no byte erasure option.

Because Flash memory can be programmed while it is in its socket on the system board, it is widely used to upgrade the BIOS ROM of the PC. Some designers believe that Flash memory will replace the hard disk as a mass storage medium.

This would increase the performance of the computer tremendously since Flash memory is semiconductor memory with access time in the range of 100ns compared with disk access time in the range of tens of milliseconds. For this to happen, flash memory’s program/erase cycles must become infinite, just like hard disks.

The program/erase cycle refers to the number of times that a chip can be erased and reprogrammed before it becomes unusable. At this time, the program/erase cycle is 100,000 for Flash and EEPROM, 1000 for UV-EPROM, and infinite for RAM and disks.

5. Mask ROM

Mask ROM refers to a type of ROM in which the contents are programmed by the IC manufacturer. In other words, it is not a user-programmable ROM.

mask rom
Mask ROM

The term mask is used in IC fabrication. Since the process is costly, mask ROM is used when the needed volume is high (hundreds of thousands) and it is absolutely certain that the contents will not change.

It is common practice to use UV-EPROM or Flash for the development phase of a project, and only afier the code/data have been finalized is the mask version of the product ordered.

What is thread ?

 A thread is a flow of execution through the process code, with its own program counter that keeps track of which instruction to execute next, system registers which hold its current working variables, and a stack which contains the execution history.

A thread shares with its peer threads few information like code segment, data segment and open files. When one thread alters a code segment memory item, all other threads see that.

A thread is also called a lightweight process. Threads provide a way to improve application performance through parallelism. Threads represent a software approach to improving performance of operating system by reducing the overhead thread is equivalent to a classical process.

Each thread belongs to exactly one process and no thread can exist outside a process. Each thread represents a separate flow of control. Threads have been successfully used in implementing network servers and web server. They also provide a suitable foundation for parallel execution of applications on shared memory multiprocessors. The following figure shows the working of a single-threaded and a multithreaded process.

Single vs Multithreaded Process

Difference between Process and Thread

S.N.ProcessThread
1Process is heavy weight or resource intensive.Thread is light weight, taking lesser resources than a process.
2Process switching needs interaction with operating system.Thread switching does not need to interact with operating system.
3In multiple processing environments, each process executes the same code but has its own memory and file resources.All threads can share same set of open files, child processes.
4If one process is blocked, then no other process can execute until the first process is unblocked.While one thread is blocked and waiting, a second thread in the same task can run.
5Multiple processes without using threads use more resources.Multiple threaded processes use fewer resources.
6In multiple processes each process operates independently of the others.One thread can read, write or change another thread's data.

Advantages of Thread

  • Threads minimize the context switching time.
  • Use of threads provides concurrency within a process.
  • Efficient communication.
  • It is more economical to create and context switch threads.
  • Threads allow utilization of multiprocessor architectures to a greater scale and efficiency.

Types of Thread

Threads are implemented in following two ways −

  • User Level Threads − User managed threads.

  • Kernel Level Threads − Operating System managed threads acting on kernel, an operating system core.

User Level Threads

In this case, the thread management kernel is not aware of the existence of threads. The thread library contains code for creating and destroying threads, for passing message and data between threads, for scheduling thread execution and for saving and restoring thread contexts. The application starts with a single thread.

User level thread

Advantages

  • Thread switching does not require Kernel mode privileges.
  • User level thread can run on any operating system.
  • Scheduling can be application specific in the user level thread.
  • User level threads are fast to create and manage.

Disadvantages

  • In a typical operating system, most system calls are blocking.
  • Multithreaded application cannot take advantage of multiprocessing.

Kernel Level Threads

In this case, thread management is done by the Kernel. There is no thread management code in the application area. Kernel threads are supported directly by the operating system. Any application can be programmed to be multithreaded. All of the threads within an application are supported within a single process.

The Kernel maintains context information for the process as a whole and for individuals threads within the process. Scheduling by the Kernel is done on a thread basis. The Kernel performs thread creation, scheduling and management in Kernel space. Kernel threads are generally slower to create and manage than the user threads.

Advantages

  • Kernel can simultaneously schedule multiple threads from the same process on multiple processes.
  • If one thread in a process is blocked, the Kernel can schedule another thread of the same process.
  • Kernel routines themselves can be multithreaded.

Disadvantages

  • Kernel threads are generally slower to create and manage than the user threads.
  • Transfer of control from one thread to another within the same process requires a mode switch to the Kernel.

Multithreading Models

Some operating system provide a combined user level thread and Kernel level thread facility. Solaris is a good example of this combined approach. In a combined system, multiple threads within the same application can run in parallel on multiple processors and a blocking system call need not block the entire process. Multithreading models are three types

  • Many to many relationship.
  • Many to one relationship.
  • One to one relationship.

Many to Many Model

The many-to-many model multiplexes any number of user threads onto an equal or smaller number of kernel threads.

The following diagram shows the many-to-many threading model where 6 user level threads are multiplexing with 6 kernel level threads. In this model, developers can create as many user threads as necessary and the corresponding Kernel threads can run in parallel on a multiprocessor machine. This model provides the best accuracy on concurrency and when a thread performs a blocking system call, the kernel can schedule another thread for execution.

Many to many thread model

Many to One Model

Many-to-one model maps many user level threads to one Kernel-level thread. Thread management is done in user space by the thread library. When thread makes a blocking system call, the entire process will be blocked. Only one thread can access the Kernel at a time, so multiple threads are unable to run in parallel on multiprocessors.

If the user-level thread libraries are implemented in the operating system in such a way that the system does not support them, then the Kernel threads use the many-to-one relationship modes.

Many to one thread model

One to One Model

There is one-to-one relationship of user-level thread to the kernel-level thread. This model provides more concurrency than the many-to-one model. It also allows another thread to run when a thread makes a blocking system call. It supports multiple threads to execute in parallel on microprocessors.

Disadvantage of this model is that creating user thread requires the corresponding Kernel thread. OS/2, windows NT and windows 2000 use one to one relationship model.

One to one thread model

Difference between User-Level & Kernel-Level Thread

S.N.User-Level ThreadsKernel-Level Thread
1User-level threads are faster to create and manage.Kernel-level threads are slower to create and manage.
2Implementation is by a thread library at the user level.Operating system supports creation of Kernel threads.
3User-level thread is generic and can run on any operating system.Kernel-level thread is specific to the operating system.
4Multi-threaded applications cannot take advantage of multiprocessing.Kernel routines themselves can be multithreaded.

Difference Between Linker and Loader

 Difference Between Linker and Loader : 

 

S.No.LINKERLOADER
1The main function of Linker is to generate executable files.Whereas main objective of Loader is to load executable files to main memory.
2The linker takes input of object code generated by compiler/assembler.And the loader takes input of executable files generated by linker.
3Linking can be defined as process of combining various pieces of codes and source code to obtain executable code.Loading can be defined as process of loading executable codes to main memory for further execution.
4Linkers are of 2 types: Linkage Editor and Dynamic Linker.Loaders are of 4 types: Absolute, Relocating, Direct Linking, Bootstrap.
5Another use of linker is to combine all object modules.It helps in allocating the address to executable codes/files.
6Linker is also responsible for arranging objects in program’s address space.Loader is also responsible for adjusting references which are used within the program.

What is refresh rate ?

 Refresh Rates

As illustrated above, a higher refresh rate refers to the frequency that a display updates the onscreen image. The time between these updates is measured in milliseconds (ms), while the refresh rate of the display is measured in hertz (Hz).

The refresh rate of your display refers to how many times per second the display is able to draw a new image. This is measured in Hertz (Hz). For example, if your display has a refresh rate of 144Hz, it is refreshing the image 144 times per second. When paired with the high frame rates produced by a GPU and CPU working together, this can result in a smoother experience and potentially higher FPS.

In order to take advantage of higher refresh rates, three of the most important components to consider are:

  • A monitor with the ability to refresh quickly.
  • A CPU that’s fast enough to provide critical game instructions, including AI, physics, game logic, and rendering data.
  • A GPU that’s fast enough to execute these instructions quickly and create the graphics you see on the screen.

The monitor can only display an image at the rate the system produces it, so it’s important that your CPU and GPU are capable of completing this process quickly. If your CPU and GPU are incapable of supplying the monitor with a sufficiently high number of frames then your monitor won’t be able to produce a high-refresh rate image regardless of how good its specs are.

If your monitor has a refresh rate of 144Hz but the GPU is only supplying 30 frames per second, that higher refresh rate is not being utilized.

What is deadlock ?

 In an operating system, a deadlock occurs when a process or thread enters a waiting state because a requested system resource is held by another waiting process, which in turn is waiting for another resource held by another waiting process.

Two types of deadlocks can be considered:

1. Resource Deadlock

Occurs when processes are trying to get exclusive access to devices, files, locks, servers, or other resources.

In Resource deadlock model, a process waits until it has received all the resources that it has requested.

The resource model is also called the AND model. In this model, a deadlock occurs if and only if there is a cycle of waiting processes, each dependent on the next process in the cycle to make progress.

Possible situation: Transaction-processing scenario

2. Communication Deadlock

Also referred to as Communication deadlock model, occurs when process A is trying to send a message to process B, which is trying to send a message to process C which is trying to send a message to A.

The communication deadlock model is also called OR model.

Evidently, it easily satisfies the Circular-wait condition for deadlock to occur.

Possible situation: Message-passing scenario


How to convert from octal to decimal

 

How to convert from octal to decimal

A regular decimal number is the sum of the digits multiplied with 10n.

Example #1

137 in base 10 is equal to each digit multiplied with its corresponding 10n:

13710 = 1×102+3×101+7×100 = 100+30+7

Octal numbers are read the same way, but each digit counts 8n instead of 10n.

Multiply each digit of the hex number with its corresponding 8n.

Example #2

37 in base 8 is equal to each digit multiplied with its corresponding 8n:

378 = 3×81+7×80 = 24+7 = 31

Example #3

7014 in base 8 is equal to each digit multiplied with its corresponding power of 8:

70148 = 7×83+0×82+1×81+4×80= 3584+0+8+4 = 3596

Example #4

112 = (1 × 8²) + (1 × 8¹) + (2 × 8⁰) = 74

Octal to decimal conversion table

Octal

base 8

Decimal

base 10

00
11
22
33
44
55
66
77
108
119
1210
1311
1412
1513
1614
1715
2016
3024
4032
5040
6048
7056
10064

 

Decimal to Octal converter ►

What is the Difference Between OMR and OCR?

 

What is the Difference Between OMR and OCR?

#OMR #OCR

The difference between OMR and OCR is that OMR is the abbreviation of optical mark recognition that is used to recognize the check and bubble marks on the paper; mostly exams and surveys, whereas OCR is optical character recognition that is used to recognize the characters from documents and collects and converts it into machine-coded language for editing it.

OMR – known as optical mark recognition, is a technology used to read marked human data. This process captures the data from documents like tests and surveys. It can deduct and read multiple choice papers, questionnaires, etc., with the help of the shaded and lined areas. OMR is also called optical mark reading. The sheets that are scanned by the OMR scanner are then processed by the OMR software. This method made grading in exams easier.

OCR- known as optical character recognition, is a technology that converts the images of any text document electronically into an encoded text in the machine. It is also known as an optical character reader. It is a method that digitizes printed texts and is a form of data entry for data records. This is done so that the data can be electronically edited and stored systematically. It can be used on any scanned documents, photo documents, billboards, text on signs, television broadcasts, etc.

How to Host a Laravel Project on Hostinger’s hPanel: A Step-by-Step Guide

How to Host a Laravel Project on Hostinger’s hPanel: A Step-by-Step Guide If you're looking to host a Laravel project on Hostinger’s hPa...