C Programming - Pointers - Discussion

Discussion Forum : Pointers - General Questions (Q.No. 4)
4.
How many bytes are occupied by near, far and huge pointers (DOS)?
near=2 far=4 huge=4
near=4 far=8 huge=8
near=2 far=4 huge=8
near=4 far=4 huge=8
Answer: Option
Explanation:
near=2, far=4 and huge=4 pointers exist only under DOS. Under windows and Linux every pointers is 4 bytes long.
Discussion:
41 comments Page 1 of 5.

Rohit said:   1 decade ago
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.

Read more: http://wiki.answers.com/Q/What_are_near_far_and_huge_pointers_in_C#ixzz1T7iNy5fX

Bijan said:   1 decade ago
A far pointer is a pointer which includes segment number. In a segmented architecture computer, far pointers are used to address the entire 1mb memory which is available under Dos.

Most programmers today (as of 2009) never use far pointers.
Instead, most programmers always use 32 bit "flat pointers".


example: int main() {

int a; a=10; printf("%d",&a); return 0;

}

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 huge pointer is a monolithic pointer to some item with a large chunk of memory, and there are no segment:offset boundaries.

Abhishek said:   7 years ago
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 the 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.
(2)

Abirami said:   3 years ago
1byte = 8 bits.
Near pointer is a 16 bit ie occupies 2 bytes.
Whereas far and huge is a 32-bit pointer i.e. 4 bytes.
So, near =2 far=4 huge=4 bytes.
(2)

Pallavi mishra said:   1 decade ago
I couldn't understand the question? if pointer takes 2 bytes in dos system, then why huge takes 4 bytes?

Abhigna said:   1 decade ago
Hardware is the physical components.

DOS is a program i.e,set of instructions.

Hence DOS is software.

Preeti said:   10 years ago
How can we use this pointer in the programming? Give example with all three pointer type.

Neel said:   9 years ago
What are near, far and huge? Whether they are simple variables or any special in DOS?

Suresh said:   1 decade ago
I'm not able to understand, please tell me brifely.

Why near occupies 2 bytes?.

Prem said:   1 decade ago
What is definition of near, far, huge? & how bytes are calculated ?


Post your comments here:

Your comments will be displayed after verification.