Static vs Shared libraries in Linux
Libraries are collection of precompiled functions which have been written to be reusable.
Libraries in Linux are classified into two types:
1) Static Libraries:- The collection of object files kept together. When a program needs a function, that is stored in static library, it includes the header file that declares the function. The compiler combines the program code and linker links the library into an execuatble code.
Static Libraries are also called as archives that ends with .a extension.
e.g. /usr/lib/libc.a is a standard C library.
Disadvantage of Static Libraries:- In the static libraries the function code is included in the executable. So when we run many applications that use the same function code, we end up with many copies of same functions in memory.
2) Shared Libraries:- When a program uses a function in a shared library, then that code does not get included in the execuatable. Instead it references to shared code that will be made available at run time. So when that program is loaded in memory to execute, the functions references are resolved and calls are maded to shared libraries which will be loaded into memory.
So many applications uses a single copy of shared libraries. Also shared libraries can be updated independently of the applications that rely on it.
Shared libraries has the form libname.so.N
name - name of library so - extension N - major revision number
Bit programming: Set , Get , Clear ,Toggle
// test a bit if it is zero or one
int8_t testBit(int8_t value,int whichBit)
{
int mask = 1 << whichBit;
if (value&mask)
{
return TRUE;
}
else return FALSE;
}
// Set a bit to one
int8_t setBit(int8_t result, int whichBit)
{
return (result |= (1<<whichBit));
}
// toggle a bit
int8_t toggleBit(int8_t result, int whichBit)
{
return (result ^= (1<<whichBit));
}
/* Clear a bit to zero */
int8_t clearBit(int8_t result, int whichBit)
{
return (result &=~ (1<<whichBit));
// test a bit if it is zero or one
int8_t testBit(int8_t value,int whichBit)
{
int mask = 1 << whichBit;
if (value&mask)
{
return TRUE;
}
else return FALSE;
}
// Set a bit to one
int8_t setBit(int8_t result, int whichBit)
{
return (result |= (1<<whichBit));
}
// toggle a bit
int8_t toggleBit(int8_t result, int whichBit)
{
return (result ^= (1<<whichBit));
}
/* Clear a bit to zero */
int8_t clearBit(int8_t result, int whichBit)
{
return (result &=~ (1<<whichBit));
No comments:
Post a Comment