SolvedQuestions
SolvedQuestions
UI thread : User-interface threads have a message pump and process messages received from
the system.
If you want to create a worker thread, pass to AfxBeginThread a pointer to the controlling
function and the parameter to the controlling function.
6) What is Deadlocks?
A deadlock occurs when two threads each lock a different variable at the same time and
then try to lock the variable that the other thread already locked. As a result, each thread
stops executing and waits for the other thread to release the variable. Because each thread
is holding the variable that the other thread wants, nothing occurs, and the threads remain
deadlocked.
Thus, In the first example, the new operator expects the 'type' and
not the size, since it also needs to call the constructor on that
type. Hence the first line gives compilation error. (1024 is not a
type.)
On the second line, you are explicitly calling the 'operator new'. In
other words, what you are doing is only the first step (allocating the
memory). The 'operator new' requires size_t which you have provided
properly (1024), and hence the code compiles properly.
Rediff
My Stack of Questions:
Basic concepts
The basic building block for communication is the socket. A socket is an endpoint
of communication to which a
name may be bound. Each socket in use has a type and an associated process.
Sockets exist within
communication domains. A communication domain is an abstraction introduced to
bundle common properties of
threads communicating through sockets. Sockets normally exchange data only
with sockets in the same domain
(it may be possible to cross domain boundaries, but only if some translation
process is performed). The
Windows Sockets facilities support a single communication domain: the Internet
domain, which is used by
processes which communicate using the Internet Protocol Suite
Two types of sockets currently are available to a user. A stream socket provides
for the bi-directional, reliable,
sequenced, and unduplicated flow of data without record boundaries.
There are several differences between a datagram socket and a stream socket.
1. Datagrams are unreliable, which means that if a packet of information gets lost
somewhere in the Internet, the sender is not told (and of course the receiver does
not know about the existence of the message). In contrast, with a stream socket,
the underlying TCP protocol will detect that a message was lost because it was
not acknowledged, and it will be retransmitted without the process at either end
knowing about this.
2. Message boundaries are preserved in datagram sockets. If the sender sends a
datagram of 100 bytes, the receiver must read all 100 bytes at once. This can be
contrasted with a stream socket, where if the sender wrote a 100 byte message, the
receiver could read it in two chunks of 50 bytes or 100 chunks of one byte.
3. The communication is done using special system calls sendto() and
receivefrom() rather than the more generic read() and write().
4. There is a lot less overhead associated with a datagram socket because
connections do not need to be established and broken down, and packets do not
need to be acknowledged. This is why datagram sockets are often used when the
service to be provided is short, such as a time-of-day service.
Broadcasting
Broadcast messages can place a high load on a network, since they force every
host on the network to service
them.
I am assuming you are referring to logical uses. A port is a logical connection method
two end points communicate with. Ports operate at the Transport layer of the OSI. For
example a VPN client connects to a VPN server over Port 1723. A socket is one end
point of a connection. Sockets are a means of plugging the application layer in. Sockets
are determined by an IP address and port number. For example, for a VPN client to
connect the client would need to use the socket determined by the port number and IP of
the local client.
A port is a transport-layer abstraction that is part of the TCP/IP suite. Each port is a 16-bit
integer; the space of ports for TCP and UDP are separate. Ports used by servers are given
reserved values (e.g., a Web server uses port number 80).
Note that after creating a socket, a program specifies a port to be used with that socket.
Q: 2. also when can two processes end up sharing the same port (except the case when
forking is done after binding to a port then parent-child share it).
Yes, two processes can share the same port. Sharing is most common in TCP because
TCP identifies a connection by 4 items:
Client IP address
Client port number
Server IP address
Server port number
Thus, two processes can provide Web service on port 80 concurrently as long as the two
TCP connections go to different clients.
Concurrent, connection oriented servers The typical server in the Internet domain
creates a stream socket and forks off a process to handle each new connection that it
receives. This model is appropriate for services which will do a good deal of reading and
writing over an extended period of time, such as a telnet server or an ftp server. This
model has relatively high overhead, because forking off a new process is a time
consuming operation, and because a stream socket which uses the TCP protocol has high
kernel overhead, not only in establishing the connection but also in transmitting
information. However, once the connection has been established, data transmission is
reliable in both directions.
Iterative, connectionless servers Servers which provide only a single message to the
client often do not involve forking, and often use a datagram socket rather than a stream
socket. Examples include a finger daemon or a timeofday server or an echo server (a
server which merely echoes a message sent by the client). These servers handle each
message as it receives them in the same process. There is much less overhead with this
type of server, but the communication is unreliable. A request or a reply may get lost in
the Internet, and there is no built-in mechanism to detect and handle this.
Single Process concurrent servers A server which needs the capability of handling
several clients simultaneous, but where each connection is I/O dominated (i.e. the server
spends most of its time blocked waiting for a message from the client) is a candidate for a
single process, concurrent server. In this model, one process maintains a number of open
connections, and listens at each for a message. Whenever it gets a message from a client,
it replies quickly and then listens for the next one. This type of service can be done with
the select system call.
Functions Library
ntohl
The Windows Sockets ntohl function converts a u_long from TCP/IP network order to
host byte order (which is little-endian on Intel processors).
Htonl
The Windows Sockets htonl function converts a u_long from host to TCP/IP network
byte order (which is big-endian).
The Windows timer is a relatively simple extension of the timer logic built into the PC's
hardware and the ROM BIOS. Back in the pre-Windows days of MS-DOS programming,
an application could implement a clock or a timer by trapping a BIOS interrupt called the
"timer tick." This interrupt occurred every 54.925 msec, or about 18.2 times per second.
This is the original 4.772720 MHz microprocessor clock of the original IBM PC divided
by 218.
Writing a bitmap to a BMP file is fairly simple if we have a handle to device-independent bitmap. We simply
write BITMAPINFOHEADER information followed by the contents of the bitmap. The three fields that we
have to set in the BITMAPINFOHEADER are the bfType which should always be "BM", the bfSize which is
the size of the bitmap including the infoheader and the bfOffBits which is the offset to the bitmap bits from
the start of the file.
If you have a device-dependent bitmap to begin with, you have to first create a DIB from it. Creating a DIB
from a DDB has already been covered in another section.
if (!hDIB)
return FALSE;
CFile file;
if( !file.Open( szFile, CFile::modeWrite|CFile::modeCreate) )
return FALSE;
lpbi = (LPBITMAPINFOHEADER)hDIB;
return TRUE;
}
reversing bits
int IntReverse(int src)
{
int ret = 0;
int bitPos;
typedef
typedef type-declaration synonym;
The typedef keyword defines a synonym for the specified type-declaration. The
identifier in the type-declaration becomes another name for the type, instead of naming
an instance of the type. You cannot use the typedef specifier inside a function definition.
In contrast to the class, struct, union, and enum declarations, typedef declarations do
not introduce new types — they introduce new names for existing types.
Example
1MB=1024KB
1024MB=1GB
Data Measurement Chart
Data Measurement Size
Bit Single Binary Digit (1 or 0)
Byte 8 bits
Kilobyte (KB) 1,024 Bytes
Megabyte (MB) 1,024 Kilobytes
Gigabyte (GB) 1,024 Megabytes
Terabyte (TB) 1,024 Gigabytes
Petabyte (PB) 1,024 Terabytes
Exabyte (EB) 1,024 Petabytes
OLE
Object Linking and Embedding. A technology for transferring and sharing
information among applications. When an object, such as an image file created
with a painting application, is linked to a compound document, such as a
spreadsheet or a document created with a word processing application, the
document contains only a reference to the object; any changes made to the
contents of a linked object are seen in the compound document. When an object is
embedded in a compound document, the document contains a copy of the object;
any changes made to the contents of the original object are not seen in the
compound document unless the embedded object is updated. See also
Automation.
The OLE classes work with the other application framework classes to provide easy
access to the ActiveX API, giving your programs an easy way to provide the power of
ActiveX to your users. Using ActiveX, you can:
Create compound documents, which allow users to create and edit documents
containing data created by multiple applications, including text, graphics,
spreadsheets, sound, or other types of data.
.INI files are plain-text files that contain configuration information. These files are used
by Windows and Windows-based applications to save information about your preferences
and operating environment. "INI" stands for initialization.
.INI files contain one or more sections. Each section begins with a section name, which is
followed by zero or more entries. An entry associates a keyname with avalue. The general
format is:
[section]
keyname=value
Comments can also be included in the file by prefacing the comment with a semicolon
(;).
Windows and Windows for Workgroups use several standard .INI files for storing
configuration information. These files are WIN.INI, SYSTEM.INI, PROTOCOL.INI,
PROGMAN.INI, CONTROL.INI, WINFILE.INI, MSMAIL.INI, SHARED.INI, and
SCHDPLUS.INI. Windows-based programs may also add sections and entries to
WIN.INI, and they may add .INI files in the Windows directory.
Because .INI files use only plain text, they can be edited using any text editor or word
processor. .INI Master also has a built-in text editor for making corrections in the .INI
files you are diagnosing.
Heap VS Data segment
VS Stack
When a program is loaded into memory, it is organized into three areas
of memory, called segments: the text segment, stack segment, and heap
segment. The text segment (sometimes also called the code segment) is
where the compiled code of the program itself resides.
The heap segment provides more stable storage of data for a program;
memory allocated in the heap remains in existence for the duration of a
program. Therefore, global variables (storage class external), and
static variables are allocated on the heap. The memory allocated in the
heap area, if initialized to zero at program start, remains zero until
the program makes use of it. Thus, the heap area need not contain
garbage.
int main()
{
int a=0,b=0;
printf("Enter two numbers:\n");
scanf("%d %^d",&a,&b);
printf("The numbers are : %d, %d\n",a,b);
return 0;
}
When you execute this program it would ask the user to enter two numbers.
But actually it assigns the value only to the integer variable a but not to
b.
Here the operator '%^' will act as assignment suppression operator and
suppress any assignments to the variable b.
How many max drives can be on machine?
Ans: There can be 26 drives only, but 2 drives are for Floppy disk and rest we
can be assigned to 24 partition.