Click here to Skip to main content
15,898,588 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,
What is the difference between "near", "far" and "huge" pointers?
Posted

The differences are only relevant on 16 bit [1] intel architectures and stopped being significant about 15 years ago.

In a nutshell virtual addresses on an Intel x86 chip have two components - a selector and an offset. The selector is an index into a table of base addresses [2] and the offset is added onto that base address. This was designed to let the processor access 20 bit (on a 8086/8, 186), 30 bit (286) or 46 bit (386 and later) virtual address spaces without needing registers that big.

So...

'near' pointers don't have a selector - they have an implied selector. They can access 64k off the virtual address space on a 286 and earlier and 4Gb of the addresss space on a 386 or later.

'far' pointers have an explicit selector. However when you do pointer arithmetic on them the selector isn't modified.

'huge' pointers have an explicit selector. When you do pointer arithmetic on them though the selector can change.

'based' pointers... oh, you didn't ask about them.

Basically ignore this. It's not worth the hassle to learn about unless you're an archaeologist.

Cheers,

Ash

[1] Okay, modern intel processors have all the old segmented guff still hanging about but the OS tends to set the selectors once and then forget about them.

[2] In real mode there is no table of base addresses, the address is just the selector multipled by 16.
 
Share this answer
 
Comments
Yuvaraj Gogoi 19-Aug-10 12:46pm    
////////////////////
'far' pointers have an explicit selector. However when you do pointer arithmetic on them the selector isn't modified.

'huge' pointers have an explicit selector. When you do pointer arithmetic on them though the selector can change.
////////////////////////

By selector, do u mean to say it using the same selector in far pointers?Then what is its difference to near pointers? It also refers to same segment!

Thanks a lot for replying!
Aescleal 19-Aug-10 18:35pm    
Near pointers refer to a selector that's implicit depending on the type of data or code you're accessing. So a near jump refers to the current selector loaded into the code segment register (CS). Likewise when you want to read data through a near pointer it refers tot he current segment loaded into the data segment register (DS).

Far and huge pointers have an explicit selector that's always loaded when you do something with the pointer. So a far jump will be relative to the selector in the pointer NOT the segment currently loaded in the CS register. Likewise a far read will be relative to the selector in the pointer NOT the segment currently loaded in the DS register.

As I said before don't worry too much about it. It's really a relic of the past and only something to worry about when porting operating system code. Application code these days doesn't have to worry about it.
Yuvaraj Gogoi 29-Aug-10 5:24am    
Thanks for your answar!
 
Share this answer
 
Comments
Yuvaraj Gogoi 19-Aug-10 12:43pm    
I have google it! But I didn't get much of the difference between far and huge pointers,except that far is not normalized and huge is normalized!
Aescleal 19-Aug-10 18:40pm    
Normalisation is the only difference between far and huge pointers. If a pointer is normalised it means that the pointer contains the minimum possible offset from the selector it refers to. Exactly what that means depends on the OS, the C compiler, phase of the moon...

As a quick example real mode programs have selectors with a base address 16 bytes apart so a huge pointer in a DOS program will never have an offset greater than 15. For contiguous blocks of memory in 16 bit windows programs huge pointers have offsets 64k apart so the offset can be up 64k - 1.
Yuvaraj Gogoi 15-Oct-10 6:15am    
Thanks for the answar!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900