Wednesday, June 22, 2011

Static v/s Dynamic Library

What is a static library?

First of all, a library is a set of functions complied into an object code that is used by applications. When we compile a program that uses a static library, the entire object code gets included in the executable code thus increasing the size of executable. Lets say, the library is altered. Now in this case, you need to recompile the library and recompile your application. The other disadvantage is that if there are several applications running that use the static library, then it leads to wastage of space as the library is included in all the executables. Static libraries are also called as archives(.a extension). Try exploring the makefile, it will have loads of .a libraries in the dependency list.

Dynamic Library:
It consists of routines or functions that are loaded at runtime if a reference exists. In this case, instead of including the entire object code, we include a reference to the library and define the rules on how to find this reference(basically tell the linker where to locate the library for eg, /usr/lib). You can keep it anywhere but just mention the path in the linker search path. They have the advantage that if your library gets changes, the application using the library need not be compiled, it just keeps running. If more than one application using this dynamic library is running, then only a single copy is loaded into the memory which is used by all the applications. These have ".so" extension.

Tuesday, March 16, 2010

Virtual Memory

Hi again. In this post Im gonna discuss about virtual memory.Yes... youll find loads of material on virtual memory on the web.For all those preparing for interviews, its a sure shot question. Its kinda interviewers favorite question... So lets hit it....

Virtual Memory:
When we open some applications on our computer like an internet browser,mp3 player,text editors etc all at the same time, the pages of these applications are brought into RAM by computer. Now lets say, there is only 64MB of RAM in your computer and lets forget the concept of virtual memory. If there was no thing called virtual memory then this would mean that when your applications occupied 64MB in your RAM, then your computer would stop obeying your orders of opening new applications. Wont that be unfair to you, u spent lotsa money on that box and it defies you....

Here comes the role of virtual memory.....
This concept is based on the fact that when you run an application, not all the pages of the application are needed at once and also that about 10-20% of the pages are required to keep the application running...
Virtual memory lets you to bring the pages required at a particular instant into RAM and swap out those which are not being used.
These swapped out pages are kept on the hard disk. In linux, we have the swap filesystem whereas in windows we have pagefile.sys for this purpose.
The user is unaware of this whole mechanism and gets an illusion that there is indefinite amount of RAM at his disposal for him to open several applicatoins.

Let me also discuss now how the various memories are organized.

CACHE-------RAM------VIRTUAL MEMORY | HARD DISK

When a page is needed, the CPU first checks the page in cache memory. If the page is not found in cache, then cpu looks up for it in RAM. If found in RAM, the CPU keeps a copy of the page in cache so that, it is available for next demand from the cache itself.
If the page is neither found in RAM nor in the Cache, then the page is loaded from the virtual memory, which resides on the hard disk, into the RAM

Wednesday, March 10, 2010

Linux - .profile file

Hey, ur all back...once again !!!
Ive been working on Linux for quite long, but with lot of discontinuities. But this time, while working I thought of learning about .profile and writing one for myself.. Better late than never suits me, isn't it... Ok, enuf talking...Lets get on, like always with BASICS!!!

What is .profile ?
This file is the first file which gets executed when you login to a shell. It has some initializations, aliases, exports etc to make you go easy while working on command line. It is present in the user's home directory and its a hidden file as it begins with a dot(.). So use ls -a.

What do we usually put in .profile ?
Lets say you have a directory /home/mydir/mydir1/ with a lot of files. Now every time you want to do some file manipulation, you obviously wouldn't want to enter the whole path again and again.So we can create an alias and put it in .profile.
alias myd= cd /home/mydir/mydir1/

Functions:
You can also create functions with arguments to simplify ur task. Lets write a function for displaying your file (using cat)
show ()
{
cat /home/mydir/mydir1/$1
}
Now if you write "show abc" from any folder, the file content will be viewed.

set -o vi
This is another command that I always put in my .profile. It enables us to use history.
You can do this by pressing Esc key and then using "k" and "j" to move backward and forward in history. Its useful, believe me...

set -o noclobber
This is again a useful command. It helps us from accidently over writing an existing file.
Lets say you have a file abc.
Now if you write ls -l > abc
You will get an error saying that abc cannot be overwritten.

export HISTSIZE=100
This enables 100 commands to be kept in history.

These are some of things that you can do.You can write if statements and write any kind of shell scripting that you wanna perform at login...

Saturday, March 6, 2010

Copying files in binary mode

Long time guys.... Yes, m really writing after a long time..i guess after 2 months...
There hasn't been learning on my side on the technical front, but a lot on the domain side..
Copying files :
Many of us would be using tools like winscp, which uses SSH for transferring files between Linux and Windows..even I use it... SSH basically does encryption and decryption before sending and receiving data respectively.It does so for secure transmission.

Now when you copy files between Windows and Linux, you should preferably use bin or binary mode.
Now comes a big "WHY" ???
I prefer it because in "text" mode, WINSCP does some conversion between end of line characters (Windows uses CR+LF(\r\n) as EOL whereas Linux uses LF(\n))
CR and LF represents bytes used to denote EOL.
Enter key generates LF.
CR is denoted by \r.

So to avoid this conversion, its better to use bin mode when you copy dumps or some other type of files which dont deal with just characters.

Ill now come up wid details on these in my next post... Thanks...

Saturday, January 9, 2010

SMTP and MIME

Hi,
Im writing after a long time.Y? Its just because i didn't learn anything new or found anything interesting to write. So , today while browsing I can across an interesting topic..

People studying engineering would know what is SMTP. But, few people know about MIME.As a student, I only knew MIME had something related to email header. So here we go.

SMTP or Simple Mail Transfer Protocol is used to send emails.These emails contain plain text and nothing else( It is because when SMTP was formulated in 1982, it had support only for US-ASCII characters).Now, when we send an email, we know that MIME adds a header to email, divides email into parts and does other technical stuff. But what if your email contains a binary file attachment? How will SMTP send the email since it contains binary information????

Now this is resolved by MIME. MIME( Multipurpose Internet Mail Extension) uses an algorithm "Base64" which does this encoding. This algorithm encodes the information, whether image,media or whatever into a form which can be understood by decoding at the recipient's end.



Saturday, September 19, 2009

Drupal - Pathauto Module

Hmm.. so u ppl are back... thank god u are :) , now I have some visits...
Without wasting any time, lets start..This time, vll learn pathauto module..So as always, lets begin by asking "WHY"....

Why are we learning this module?
You might have noticed, when you create a page or a story, it is allocated a URL automatically which by default is node/1 or node/2 and so on.. When your website is live, u obvioulsy wouldn't want to have such un-meaningful URLs. It looks more meaningful, if the URLs contain the type of information that the page displays.
So it time to add some meaning to our URLs..

Here we go now ...

1. So as described in my previous posts, u need to download this DHTML module( just goto drupal.org, click on modules do a search with DHTML menu), unzip it and save it in C:\wamp\www\drupal\sites\all\modules.
2. Make sure that you download the correct version.
3. Once you have downloaded it, start the WAMP server and go to http://localhost/drupal .
4. Now login into your account.
5. Goto Administer- Site Building - Module.
6. Click on URL aliases under Path heading.
7. Click on Add Alias.
8. On Existing Alias path, give the automatically generated path( node/1 ..)
9. On Path Alias, give a meaningful name to be associated with a particular page.
10. Click on Create new Alias and BINGO... there u go..

Thats it for now, keep giving some meaningful names to your pages or polls or wtever... I'll be back with some other important modules...

Happy naming :)....


Wednesday, September 16, 2009

Drupal - DHTML Menu Module

This is the simplest module that ive come across during my course fo learning Drupal.

Why are we learning this module?
Thats the first question I believe you shud ask yourself...In case uve not asked yourselves :) , lemme answer it since I raised it at the first place.. :)
Oh k.. If youve explored or played with drupal, you would have noticed that when you click on the parent menu, a new page opens.This increases the number of pages t be opened and makes the user wait. By using DHTML Menu, the sub menu opens up below the parent item and without opening or refreshing the current page.

Here we go, as always :)

1. So as described in my previous posts, u need to download this DHTML module( just goto drupal.org, click on modules do a search with DHTML menu), unzip it and save it in C:\wamp\www\drupal\sites\all\modules.
2. Make sure that you download the correct version.
3. Once you have downloaded it, start the WAMP server and go to http://localhost/drupal .
4. Now login into your account.
5. Goto Administer- Site Building - Module.
6. Check DHTML Menu and click on save configuration
7. Now again goto Administer- Site Configuration(Click on By Module on the top) - DHTML Menu.
8. Now you can check animate sliding effect and decide which menu you want to have DHTML effect.
9. Now keep playing with the options that you see and try to get the effect which suits your needs.

Ill come up with more modules in my next post...