0% found this document useful (0 votes)
39 views

Additional Course Material: Computer Basics, Hardware and Software

This document provides information about dynamic memory allocation in C programming. It explains that calloc() is used to allocate storage for variables at runtime. Calloc() takes the number of elements and size of each element as arguments and returns a pointer to the allocated memory, which is initialized to zeros. Sizeof() returns the size of a variable, which is needed for calloc() to determine how much memory to allocate. Free() deallocates the memory assigned to a variable back to the system. An example shows calloc() being used to allocate space for 10 structures of type date, with the sizeof operator determining the size of each structure.

Uploaded by

sayhigaurav07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Additional Course Material: Computer Basics, Hardware and Software

This document provides information about dynamic memory allocation in C programming. It explains that calloc() is used to allocate storage for variables at runtime. Calloc() takes the number of elements and size of each element as arguments and returns a pointer to the allocated memory, which is initialized to zeros. Sizeof() returns the size of a variable, which is needed for calloc() to determine how much memory to allocate. Free() deallocates the memory assigned to a variable back to the system. An example shows calloc() being used to allocate space for 10 structures of type date, with the sizeof operator determining the size of each structure.

Uploaded by

sayhigaurav07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

AMIE(I) STUDY CIRCLE(REGD.

)
A Focused Approach
Before taking printout of this chapter, please ensure that this material has not been covered
in the printed course material provided to you (by us).

Additional Course Material


Computer Basics, Hardware and Software
MODEM
The word "modem" is a contraction of the words modulator-demodulator. A modem is
typically used to send digital data over a phone line.
The sending modem modulates the data into a signal that is compatible with the phone line,
and the receiving modem demodulates the signal back into digital data. Wireless modems
convert digital data into radio signals and back.
Modems came into existence in the 1960s as a way to allow terminals to connect to
computers over the phone lines. A typical arrangement is shown below:

People got along at 300 bps for quite a while. The reason this speed was tolerable was
because 300 bps represents about 30 characters per second, which is a lot more characters per
second than a person can type or read. Once people started transferring large programs and
images to and from bulletin board systems, however, 300 bps became intolerable. Modem
speeds went through a series of steps at approximately two-year intervals:
300 bps - 1960s through 1983 or so
1200 bps - Gained popularity in 1984 and 1985
2400 bps
9600 bps - First appeared in late 1990 and early 1991
19.2 kilobits per second (Kbps)
28.8 Kbps
33.6 Kbps
56 Kbps - Became the standard in 1998
ADSL, with theoretical maximum of up to 8 megabits per second (Mbps) - Gained
popularity in 1999
POST BOX NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : [email protected] 1
TOTAL PAGES:
AMIE(I) STUDY CIRCLE(REGD.)
A Focused Approach
300-bps Modems
We'll use 300-bps modems as a starting point because they are extremely easy to understand.
A 300-bps modem is a device that uses frequency shift keying (FSK) to transmit digital
information over a telephone line. In frequency shift keying, a different tone (frequency) is
used for the different bits.
When a terminal's modem dials a computer's modem, the terminal's modem is called the
originate modem. It transmits a 1,070-hertz tone for a 0 and a 1,270-hertz tone for a 1. The
computer's modem is called the answer modem, and it transmits a 2,025-hertz tone for a 0
and a 2,225-hertz tone for a 1. Because the originate and answer modems transmit different
tones, they can use the line simultaneously. This is known as full-duplex operation. Modems
that can transmit in only one direction at a time are known as half-duplex modems, and they
are rare.
Let's say that two 300-bps modems are connected, and the user at the terminal types the letter
"a." The ASCII code for this letter is 97 decimal or 01100001 binary. A device inside the
terminal called a UART (universal asynchronous receiver/transmitter) converts the byte into
its bits and sends them out one at a time through the terminal's RS-232 port (also known as a
serial port). The terminal's modem is connected to the RS-232 port, so it receives the bits one
at a time and its job is to send them over the phone line.

Faster Modems
Faster modems are used by Internet users every day, notably cable modems and ADSL
modems. In telecommunications, "radio modems" transmit repeating frames of data at very
high data rates over microwave radio links. Some microwave modems transmit more than a
hundred million bits per second. Optical modems transmit data over optical fibers. Most
intercontinental data links now use optical modems transmitting over undersea optical fibers.
Optical modems routinely have data rates in excess of a billion (1x109) bits per second.
In order to create faster modems, modem designers had to use techniques far more
sophisticated than frequency-shift keying. First they moved to phase-shift keying (PSK), and
then quadrature amplitude modulation (QAM). These techniques allow an incredible
amount of information to be crammed into the 3,000 hertz of bandwidth available on a
normal voice-grade phone line. 56K modems, which actually connect at something like 48
Kbps on anything but absolutely perfect lines, are about the limit of these techniques (see the
links at the end of this article for more information).

MULTIPLEXING
In electronics, telecommunications and computer networks, multiplexing (short muxing) is a
term used to refer to a process where multiple analog message signals or digital data str eams
are combined into one signal. The aim is to share an expensive resource. For example, in
electronics, multiplexing allows several analog signals to be processed by one analog-to-
digital converter (ADC), and in telecommunications, several phone calls may be transferred
using one wire. In communications, the multiplexed signal is transmitted over a

P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : [email protected] 2
AMIE(I) STUDY CIRCLE(REGD.)
A Focused Approach
communication channel, which may be a physical transmission medium. The multiplexing
divides the capacity of the low-level communication channel into several higher-level logical
channels, one for each message signal or data stream to be transferred. A reverse process,
known as demultiplexing, can extract the original channels on the receiver side.

A device that performs the multiplexing is called a multiplexer (MUX), and a device that
performs the reverse process is called a demultiplexer (DEMUX).
The two most basic forms of multiplexing are time-division multiplexing (TDM) and
frequency-division multiplexing (FDM).

An example of multiplexing

Frequency Division Multiplexing. (FDM)


This technique permits a fixed frequency band to every user in the complete channel
bandwidth. Such frequency slot is allotted continuously to that user. As an example consider
that the channel bandwidth is 1 MHz. Let there be ten users, each requiring upto 100 KHz
bandwidth. Then the complete channel bandwidth of 1 MHz can be divided into ten
frequency bands, i.e. each of 100 kHz and every user can be allotted one independent
frequency band. This technique is known as Frequency Division Multiplexing (FDM). It is
mainly used for modulated signal. This is due to the fact that a modulated signal can be
placed in any frequency band by just changing the carrier frequency. However, at the
receiver, these frequency multiplexed signals can be separated by the use of tuned circuits
(i.e., bandpass filters) of their respective frequency band. And for every band, there are
independent tuned circuits and demodulators.

Time division Multiplexing (TDM)


In case of Time Division Multiplexing (TDM), the complete channel band- width is allotted
to one user for a fixed time slot. As an example, if there are ten users, then every user can be
given the time slot of one second. Thus, complete channel can be used by each user for one
second time in every ten seconds. This technique is suitable for digital signals. Because
digital signals are transmitted intermittently and the time spacing between two successive
digital code words can be utilized by other signals.

C Programming

P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : [email protected] 3
AMIE(I) STUDY CIRCLE(REGD.)
A Focused Approach
Example

What is dynamic memory allocation?

Solution

Dynamic Memory Allocation


It is desirable to dynamically allocate space for variables at runtime. It is wasteful when
dealing with array type structures to allocate so much space when declared, eg,
struct client clients[100];
This practice may lead to memory contention or programs crashing. A far better way is to
allocate space to clients when needed.
The C programming language allows users to dynamically allocate and deallocate memory
when required. The functions that accomplish this are calloc(), which allocates memory to a
variable, sizeof, which determines how much memory a specified variable occupies, and
free(), which deallocates the memory assigned to a variable back to the system.

Example

Explain calloc(), sizeof and free().

Solution

CALLOC
This function is used to allocate storage to a variable whilst the program is running. The
function takes two arguments that specify the number of elements to be reserved, and the size
of each element (obtained from sizeof) in bytes. The function returns a character pointer
(void in ANSI C) to the allocated storage, which is initialized to zero's.
struct date *date_pointer;
date_pointer = (struct date *) calloc( 10, sizeof(struct date) );
The (struct date *) is a type cast operator which converts the pointer returned from calloc to a
character pointer to a structure of type date. The above function call will allocate size for ten
such structures, and date_pointer will point to the first in the chain.
SIZEOF
The sizeof() function returns the memory size of the requested variable. This call should be
used in conjunction with the calloc() function call, so that only the necessary memory is
allocated, rather than a fixed size. Consider the following,
struct date {
int hour, minute, second;
};
int x;

P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : [email protected] 4
AMIE(I) STUDY CIRCLE(REGD.)
A Focused Approach
x = sizeof( struct date );
x now contains the information required by calloc() so that it can allocate enough memory to
contain another structure of type date.
FREE
When the variables are no longer required, the space which was allocated to them by calloc
should be returned to the system. This is done by,
free( date_pointer );
Other C calls associated with memory are,
alloc allocate a block of memory from the heap
malloc allocate a block of memory, do not zero out
zero zero a section of memory
blockmove move bytes from one location to another

P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : [email protected] 5

You might also like