When should a far pointer be used in ?
When to Use Far Pointers: A Guide for Programmers
Sometimes you can get away with using a small memory model in most of a given program. There might be just a few things that don’t fit in your small data and code segments. When that happens, you can use explicit far pointers and function declarations to get at the rest of memory. A far function can be outside the 64KB segment most functions are shoehorned into for a small-code model. (Often, libraries are declared explicitly far, so they’ll work no matter what code model the program uses.) 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.
In modern computer systems, the use of far pointers is rare, as most systems use flat memory models where all memory addresses are equally accessible. However, far pointers can still be useful in some specific cases, such as:
-
In legacy systems that use segmented memory models: In these systems, memory is divided into segments, and pointers are used to address data within a specific segment. Far pointers are necessary to access data that is located in a different segment than the pointer itself.
-
When working with large data structures: Far pointers can be used to access large data structures that cannot fit in the memory segment pointed to by a near pointer.
-
When interfacing with hardware devices: Some hardware devices require far pointers to access memory-mapped I/O locations that are located outside of the processor's address space.
In general, the use of far pointers should be avoided whenever possible, as they can introduce additional complexity and reduce program performance. Only use far pointers when they are necessary to address specific memory-related problems that cannot be solved using near pointers or other techniques.