Late and Early binding in c++

1,491 views 28 slides May 29, 2018
Slide 1
Slide 1 of 28
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28

About This Presentation

Example and code


Slide Content

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 Animals0
l(gWsnw
osrdpo(?r"#
0
no(id--d
1oepdgy !1d--dv?rW/
2
2/
s?idbys?"#
0
.?sbyWpd3y/
oepdr/
y4d5r/
yd6.dpo(?r"#/dddaaddvy Whd
gs?rs?e
vi( ?d7/
2
{
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
accurate

27

28
Tags