what are far pointers?



what are far pointers?..

Answer / abhijeet kankani

A near pointer is a 16 bit pointer to an object contained in
the current segment, be it code segment, data segment, stack
segment, or extra segment. The compiler can generate code
with a near pointer and does not have to concern itself with
segment addressing, so using near pointers is fastest, and
generates smallest code. The limitation is that you can only
access 64kb of data at a time, because that is the size of a
segment - 64kb. A near pointer contains only the 16 bit
offset of the object within the currently selected segment.

A far pointer is a 32 bit pointer to an object anywhere in
memory. In order to use it, the compiler must allocate a
segment register, load it with the segment portion of the
pointer, and then reference memory using the offset portion
of the pointer relative to the newly loaded segment
register. This takes extra instructions and extra time, so
it is the slowest and largest method of accessing memory,
but it can access memory that is larger than 64kb,
sometimes, such as when dealing with video memory, a needful
thing. A far pointer contains a 16 bit segment part and a 16
bit offset part. Still, at any one instant of time, without
"touching" segment registers, the program only has access to
four 64kb chunks, or segments of memory. If there is a 100kb
object involved, code will need to be written to consider
its segmentation, even with far pointers.

Now, segments overlap. Each segment is 64kb in length, but
each one overlaps the next and the prior by 65520 bytes.
That means that every address in memory can be addressed by
64kb-1 different combinations of segment:offset pairs. The
result is that the total addressible memory was only 1mb,
and the total usable memory address space was 500kb to
600kb. That sounds odd, but Intel built it, Microsoft wrote
it, and DOS/Windows 3.1 grew up around it. I still have that
computer, and it still works just fine, thank you. :-)>

Now the huge pointer. The far pointer suffers because you
can not just add one to it and have it point the the next
item in memory - you have to consider segment:offset rules,
because of the 16 byte offset issue. The huge pointer is a
monolithic pointer to some item with a large chunk of
memory, and there are no segment:offset boundaries.
Beautiful - huhh?? - well, in order to get that, the pointer
to segment:offset calculation has to be done every time you
reference the pointer. It does allow you to create and
manipulate a single monolithic object that is greater than
64kb, but it has its costs.

Is This Answer Correct ?    5 Yes 0 No

Post New Answer

More C Interview Questions

CAN ANYONE PLEASE HELP ON THIS PROGRAM FOR MY EXAM..TQ Write a C program to help a H’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the H’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the H’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80 Your program must do the following task below: a. Define the data structs, menu item types with two components: menu item of type string and menu price of type double. Use an array to declare the data structs. b. Function get data to loads the data into the array menu list. c. Function show menu to show the different breakfast items offered by the restaurant and tell the user how to select the items. d. Function print receipt to calculates and prints the customer receipt. The billing amount should include a 5% tax. e. Format your output with two decimal places. The name of each item in the output must be left-justify. You may assume that the user selects only one item of a particular type. f. The two sample output as shown: Welcome to HiFi’s Restaurant 1 Bacon and Egg $3.45 1 Muffin $2.20 1 Coffee $1.50 Tax 5% $0.35 Amount Due $7.50

1 Answers  


What is volatile variable in c?

0 Answers  


1. Write the function int countchtr(char string[ ], int ch); which returns the number of times the character ch appears in the string. Example, the call countchtr(“She lives in NEWYORK”, ‘e’) would return 3.

4 Answers  


write a program of bubble sort using pointer?

3 Answers   TCS,


write a string copy function routine?

2 Answers  






How to use c/c++ code in JAVA

10 Answers   CDAC, IBM, Satyam, Scope International,


Explain how are portions of a program disabled in demo versions?

0 Answers  


What is pragma c?

0 Answers  


why use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above

0 Answers  


What will be the output of the following program #include<stdio.h> void main() { int i=20; i-=i+++++i++; printf("%d",i); }

5 Answers  


Explain how can I convert a string to a number?

0 Answers  


/*program to calculate hra,da in salary if salary less than 10000 then hra15%,da13% otherwise hra20%,da18%/*

6 Answers  


Categories