Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Near and Far pointers

Tags:

c++

c

pointers

What is difference between our usual pointers(ones which we normally use), near pointers and far pointers and is there a practical usage for near and far pointers in present day C/C++ systems? Any practical scenario which necessiates use of these specific pointers and not other c,c++ semantics will be very helpful.

like image 856
Alok Save Avatar asked Oct 06 '10 06:10

Alok Save


People also ask

What is far pointer and example?

In 16-bit x86 For example, in an Intel 8086, as well as in later processors running 16-bit code, a far pointer has two parts: a 16-bit segment value, and a 16-bit offset value. A linear address is obtained by shifting the binary segment value four times to the left, and then adding the offset value.

What is meant by near pointer?

Near pointer is a pointer which is used to bit address of up to 16 bits in a given section of the computer memory that is 16 bit enabled. It can only access data of a small size of about 64 kb in a given period, which is the main disadvantage of this.

What is difference between far and huge pointer?

Huge Pointer It is a pointer which is similar to far pointer in terms of size because, both are 32-bit address. The huge pointer can be incremented without suffering with segment work round.

When should a far pointer be used?

A far pointer can refer to information outside the 64KB data segment. Typically, such pointers are used with farmalloc() and such, to manage a heap separate from where all the rest of the data lives. If you use a small-data, large-code model, you should explicitly make your function pointers far.


1 Answers

The near and far keywords have their origin in the segmented memory model that Intel had before. The near pointers could only access a block of memory originally around 64Kb in size called a segment whereas the far pointers could go outside of that range consisting of a segment and offset in that segment. The near pointers were much faster than far pointers so therefore in some contexts it paid off to use them.

Nowadays with virtual memory near and far pointers have no use.

EDIT:Sorry if I am not using the correct terms, but this is how I remembered it when I was working with it back in the day :-)

like image 158
AndersK Avatar answered Sep 19 '22 04:09

AndersK