What is the difference between far and near?

As described at the beginning of this chapter, some compilers for PC compatibles use two types of pointers. near pointers are 16 bits long and can address a 64KB range. far pointers are 32 bits long and can address a 1MB range. near pointers operate within a 64KB segment. There’s one segment for function addresses and one segment for data. far pointers have a 16-bit base (the segment address) and a 16-bit offset. The base is multiplied by 16, so a far pointer is effectively 20 bits long. Before you compile your code, you must tell the compiler which memory model to use. If you use a smallcode memory model, near pointers are used by default for function addresses. That means that all the functions need to fit in one 64KB segment. With a large-code model, the default is to use far function addresses. You’ll get near pointers with a small data model, and far pointers with a large data model. These are just the defaults; you can declare variables and functions as explicitly near or far.  far pointers are a little slower. Whenever one is used, the code or data segment register needs to be swapped out. far pointers also have odd semantics for arithmetic and comparison. For example, the two far pointers in the preceding example point to the same address, but they would compare as different! If your program fits in a small-data, small-code memory model, your life will be easier.   

Showing Answers 1 - 1 of 1 Answers

umesh ram sharma

  • Sep 3rd, 2006
 

atthe time of 8086 , the processor operate in real modebt after that as more processor develop then there are two type of mode.2nd one is protected mode.in real mode the processor canuse only 1mb bt in protected mode one can use memory more then 1mb.

as the computer boot ,if it come in cmd prompt,like win95 etc., it menas by default they are in real mode ,when v use dos mode c, v are in real mode, so v can access only 1mb of memory .so, to access memory more than 1mb v have to specifiy that that memory belong to protected mode ,for this v have to declare FAR pointer.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions