KEMBAR78
Late and Early binding in c++ | PPT
1
By
Fazal ur Rehman
2
3
Binding
what is
binding??
4
What is Binding ?
• Binding refers to the process that is used to
convert identifiers (such as variable and
function names) into machine language
addresses.
• Although binding is used for both variables
and functions, but we have to focus on
function binding.
5
6
topic
•
Late And Early
Binding
7
Early/Static binding
• Most of the function calls the compiler
encounters will be direct function calls. A direct
function call is a statement that directly calls a
function.
• For example:
8
Early/Static binding
• Direct function calls can be resolved using a process
known as early binding.•
• Early binding (also called static binding) means the
compiler is able to directly associate the identifier
name (such as a function or variable name) with a
machine address.
• All functions have a unique machine address. So
when the compiler encounters a function call, it
replaces the function call with a machine language
instruction that tells the CPU to jump to the address
of the function.
9
10
Early binding
• In add() , Subtract() and multiply() are all
direct function calls, the compiler will use
early binding to resolve the add() , multiply(),
and subtract() function call.
• The compiler will replace the add() function
call with an instruction that tell the CPU to
jump to the address of the add() function.
• Same hold true for Subtract() and multiply.
11
12
#include <iostream>
using namespace std;
class Animals
{
public:
void sound()
{
cout << "This
is parent class" << endl;
}
};
class Dogs : public Animals
{
public:
void sound()
{
cout <<
"Dogs bark" << endl;
}
};
int main()
{
Animals *a;
Dogs d;
a= &d;
a -> sound(); // early
binding
return 0;
}
{
public:
void sound()
{
cout <<
"Dogs bark" << endl;
}
};
int main()
{
Animals *a;
Dogs d;
a= &d;
a -> sound(); // early
binding
return 0;
}
13
14
advantagEs: ·
Easy to Implement: The security filter becomes a
simple Boolean query over ACL fields.  "Access
Control List."
Search engines are very good at executing Boolean
queries ·
Accurate Counts: Because the query itself is
modified, the search engine will automatically compute
correct counts for:
Total number of documents - only those documents
to which the user has read access
Facet counts (note: “facets” and “navigators” are the
same thing in search)
High Performance: If implemented correctly, early
binding can be implemented with minimal impact on
performance.
15
DisaDvantages:
Requires Indexing the ACL: There is a lot of hard
work just getting the access control list out of the
original content source (in the correct format) and
writing it into the search engine
Very Large Queries: Some search engines don’t like to
execute very large queries of 100’s or even 1000’s of
terms (i.e. a long list of all of the groups to which a user
is a member) ·
ACL Changes Must be Re-Indexed: A change in an
ACL will take longer to be reflected in the search results,
because the document must be re-indexed before the
changes take effect.
16
Late binDing
17
Late/Dynamic Binding
• In some programs, it is not possible to know
which function will be called until runtime (when
the program is run). This is known as late
binding (or dynamic binding).
• For example:
18
Late/Dynamic Binding
• Calling a function via a function pointer is
also known as an indirect function call.
• In C++, one way to get late binding is to use
function pointers.
• A function pointer is a type of pointer that points
to a function instead of a variable.
19
20
21
Late binding
Late binding is slightly less efficient since it
involve an extra level of indirection
With early binding the CPU can jump directly to
the function address. With late binding the
program has read the address held in the pointer
at jump to that address.
This involve on extra step making it slightly
slower.
However the advantage of late binding is that it
is more flexible than early binding because
decision about what function to call don’t to
made until run time.
22
23
#include <iostream>
using namespace std;
class Animals
{
public:
virtual void
sound()
{
cout <<
"This is parent class" << endl;
}
};
class Dogs : public Animals
{
public:
void sound()
{
cout <<
"Dogs bark" << endl;
}
};
int main()
{
Animals *a;
Dogs d;
a= &d;
a -> sound();
return 0;
}
24
25
advantages:
No need to index the ACL;;In many cases, simply asking
a content source: “Does this user have access to this
document” may be easier to implement
ACL Changes Immediately Reflected in Search Results: ACLs
are not indexed; therefore, documents do not need to be re-
indexed when ACLs change
Can Handle Any Complex Security Model: Since access
is checked document-by-document, late binding can be
programmed to handle any arbitrarily complex security
model.
26
disadvantages:
Extremely Slow: Documents from the search results
need to be individually checked.
This can mean having to check thousands or millions of
documents
Since all checks are against the original content source,
this means search performance will be very slow
Inaccurate Counts: To improve performance, total
document counts and facet counts are often estimated
Typically, late-binding systems will only check enough
documents to fill out a page of results
This means that the total document count (thousands
or millions) and the facet counts are often estimates,
based on statistical distributions, and are not fully
27
28

Late and Early binding in c++

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
    What is Binding? • Binding refers to the process that is used to convert identifiers (such as variable and function names) into machine language addresses. • Although binding is used for both variables and functions, but we have to focus on function binding. 5
  • 6.
  • 7.
  • 8.
    Early/Static binding • Mostof the function calls the compiler encounters will be direct function calls. A direct function call is a statement that directly calls a function. • For example: 8
  • 9.
    Early/Static binding • Directfunction calls can be resolved using a process known as early binding.• • Early binding (also called static binding) means the compiler is able to directly associate the identifier name (such as a function or variable name) with a machine address. • All functions have a unique machine address. So when the compiler encounters a function call, it replaces the function call with a machine language instruction that tells the CPU to jump to the address of the function. 9
  • 10.
  • 11.
    Early binding • Inadd() , Subtract() and multiply() are all direct function calls, the compiler will use early binding to resolve the add() , multiply(), and subtract() function call. • The compiler will replace the add() function call with an instruction that tell the CPU to jump to the address of the add() function. • Same hold true for Subtract() and multiply. 11
  • 12.
    12 #include <iostream> using namespacestd; class Animals { public: void sound() { cout << "This is parent class" << endl; } }; class Dogs : public Animals { public: void sound() { cout << "Dogs bark" << endl; } }; int main() { Animals *a; Dogs d; a= &d; a -> sound(); // early binding return 0; } { public: void sound() { cout << "Dogs bark" << endl; } }; int main() { Animals *a; Dogs d; a= &d; a -> sound(); // early binding return 0; }
  • 13.
  • 14.
    14 advantagEs: · Easy toImplement: The security filter becomes a simple Boolean query over ACL fields.  "Access Control List." Search engines are very good at executing Boolean queries · Accurate Counts: Because the query itself is modified, the search engine will automatically compute correct counts for: Total number of documents - only those documents to which the user has read access Facet counts (note: “facets” and “navigators” are the same thing in search) High Performance: If implemented correctly, early binding can be implemented with minimal impact on performance.
  • 15.
    15 DisaDvantages: Requires Indexing theACL: There is a lot of hard work just getting the access control list out of the original content source (in the correct format) and writing it into the search engine Very Large Queries: Some search engines don’t like to execute very large queries of 100’s or even 1000’s of terms (i.e. a long list of all of the groups to which a user is a member) · ACL Changes Must be Re-Indexed: A change in an ACL will take longer to be reflected in the search results, because the document must be re-indexed before the changes take effect.
  • 16.
  • 17.
  • 18.
    Late/Dynamic Binding • Insome programs, it is not possible to know which function will be called until runtime (when the program is run). This is known as late binding (or dynamic binding). • For example: 18
  • 19.
    Late/Dynamic Binding • Callinga function via a function pointer is also known as an indirect function call. • In C++, one way to get late binding is to use function pointers. • A function pointer is a type of pointer that points to a function instead of a variable. 19
  • 20.
  • 21.
  • 22.
    Late binding Late bindingis slightly less efficient since it involve an extra level of indirection With early binding the CPU can jump directly to the function address. With late binding the program has read the address held in the pointer at jump to that address. This involve on extra step making it slightly slower. However the advantage of late binding is that it is more flexible than early binding because decision about what function to call don’t to made until run time. 22
  • 23.
    23 #include <iostream> using namespacestd; class Animals { public: virtual void sound() { cout << "This is parent class" << endl; } }; class Dogs : public Animals { public: void sound() { cout << "Dogs bark" << endl; } }; int main() { Animals *a; Dogs d; a= &d; a -> sound(); return 0; }
  • 24.
  • 25.
    25 advantages: No need toindex the ACL;;In many cases, simply asking a content source: “Does this user have access to this document” may be easier to implement ACL Changes Immediately Reflected in Search Results: ACLs are not indexed; therefore, documents do not need to be re- indexed when ACLs change Can Handle Any Complex Security Model: Since access is checked document-by-document, late binding can be programmed to handle any arbitrarily complex security model.
  • 26.
    26 disadvantages: Extremely Slow: Documentsfrom the search results need to be individually checked. This can mean having to check thousands or millions of documents Since all checks are against the original content source, this means search performance will be very slow Inaccurate Counts: To improve performance, total document counts and facet counts are often estimated Typically, late-binding systems will only check enough documents to fill out a page of results This means that the total document count (thousands or millions) and the facet counts are often estimates, based on statistical distributions, and are not fully
  • 27.
  • 28.