What I learned…

From today onwards I want to update my post about my learning per day

1) 30-Mar-2010:
– Map and Multimaps: Had a quick look on the STL reference book and still need to do practice
– Why we should not throw exception in dtor
– Tier1,Tier2 applications

Client/Server model FAQ

These three are the FAQ for client/Server model….

Subject: 1. What is a Two-Tier Architecture?
A two-tier architecture is where a client talks directly to a server, with no intervening server. It is typically used in small environments (less than 50 users). A common error in client/server development is to prototype an application in a small, two-tier environment, and then scale up by simply adding more users to the server. This approach will usually result in an ineffective system, as the server becomes overwhelmed. To properly scale to hundreds or thousands of users, it is usually necessary to move to a three-tier architecture.

Subject: 2. What is a Three-Tier Architecture?
A three-tier architecture introduces a server (or an “agent”) between the client and the server. The role of the agent is manyfold. It can provide translation services (as in adapting a legacy application on a mainframe to a client/server environment), metering services (as in acting as a transaction monitor to limit the number of simultaneous requests to a given server), or intellegent agent services (as in mapping a request to a number of different servers, collating the results, and returning a single response to the client.

Subject: 3. What is Middleware?
Connectivity allows applications to transparently communicate with other programs or processes, regardless of their location. The key element of connectivity is the network operating system (NOS). NOS provides services such as routing, distribution, messaging, file and print, and network management services. NOS rely on communication protocols to provide specific services. The protocols are divided into three groups: media, transport and client-server protocols. Media protocols determine the type of physical connections used on a network (some examples of media protocols are Ethernet, Token Ring, Fiber Distributed Data Interface (FDDI), coaxial and twisted-pair). A transport protocol provides the mechanism to move packets of data from client to server (some examples of transport protocols are Novell’s IPX/SPX, Apple’s AppleTalk, Transmission Control Protocol/ Internet Protocol (TCP/IP), Open Systems Interconnection (OSI) and Government Open Systems Interconnection Profile(GOSIP)). Once the physical connection has been established and transport protocols chosen, a client-server protocol is required before the user can access the network services. A client-server protocol dictates the manner in which clients request information and services from a server and also how the server replies to that request (some examples of client- server protocols are NetBIOS, RPC, Advanced Program-to-Program Communication (APPC), Named Pipes, Sockets, Transport Level Interface (TLI) and Sequenced Packet Exchange (SPX)).

STL: Vector size Vs capacity Vs max_size

Vectors have different methods to return the size details:
size:
Returns the number of elements in the vector container.

This is the number of actual objects held in the vector, which is not necessarily equal to its storage capacity. Vectors automatically reallocate their storage space when needed or when requested with member resize. To retrieve the current storage capacity of a vector you can call to its member capacity.
capacity:
Returns the size of the allocated storage space for the elements of the vector container.

Notice that, in vectors, the capacity is not necessarily equal to the number of elements that conform the underlying vector content (this can be obtained with member vector::size), but the capacity of the actual allocated space, which is either equal or greater than the content size.

Notice also that this capacity does not suppose a limit to the size of the vector. If more space is required to accomodate new elements in the vector, the capacity is automatically expanded, or can even be explicitly modified by calling member vector::reserve.

The real limit on the size a vector object can reach is returned by member vector::max_size.
max_size:
Returns the maximum number of elements that the vector container can hold.

This is not the amount of storage space currently allocated to the vector (this can be obtained with member vector::capacity), but the maximum potential size the vector could reach due to system or library implementation limitations.
Example:

[mingle]/home/rjanagam/CPP% cat stl_vector_sizes.cpp
#include
#include

using namespace std;

int main(void)
{

vector v;
v.reserve(5);
cout<< " size=" << v.size()<< ":capacity="<<v.capacity()<<":max_size="<<v.max_size()<<endl;
vector t;
cout<< " size=" << v.size()<< ":capacity="<<t.capacity()<<":max_size="<<t.max_size()<<endl;
vector r(5);
cout<< " size=" << r.size()<< ":capacity="<<r.capacity()<<":max_size="<<r.max_size()<<endl;
vector s(5);
s[0]=1,s[1]=2;
cout<< " size=" << s.size()<< ":capacity="<<s.capacity()<<":max_size="<<s.max_size()<<endl;
vector w;
w.push_back(1);
cout<< " size=" << w.size()<< ":capacity="<<w.capacity()<<":max_size="<<w.max_size()<<endl;
vector b;
for (int i=0;i<31;i++)
b.push_back(1);
cout<< " size=" << b.size()<< ":capacity="<<b.capacity()<<":max_size="<<b.max_size()<<endl;
vector x;
cout<< " size=" << x.size()<< ":capacity="<<x.capacity()<<":max_size="<<x.max_size()<<endl;
}

[mingle]/home/rjanagam/CPP% a.out
size=0:capacity=5:max_size=1073741823
size=0:capacity=0:max_size=1073741823
size=5:capacity=5:max_size=1073741823
size=5:capacity=5:max_size=1073741823
size=1:capacity=32:max_size=1073741823
size=31:capacity=32:max_size=1073741823
size=0:capacity=0:max_size=1073741823

Me back…

Me back after long time since I decided to post blogs even from office also. My PC’s harddisk is crashed last month and still its needs to be repaired. So from today onwards I will post from office also.