What is the use of the keyword "far" in Delphi?

Not knowing that I typed "far" instead of "var" in my mistake. I noticed that the keyword is in bold, which gives me thoughts that this is part of the Delphi syntax.

Does anyone know anything about the keyword "far"?

+4
source share
3 answers

In 32-bit versions of Delphi (Delphi 2 and later) means nothing. It was used in 16-bit programming to indicate the location of a segment.

It is still in the language strictly for backward compatibility with very old legacy code.

From the old Delphi 7 help file, topic "Call Conventions":

"Directives nearby, far and exported, refer to calling conventions in 16-bit Windows programming. They do not affect 32-bit applications and are only supported for backward compatibility."

+11
source

As Ken White explained, it is used only in 16-bit applications.

As a 16-bit pointer, 64 KB of memory can be addressed, memory segments are used to access more memory. A processor has four segment registers, so that it can simultaneously have four active segments, a code segment (cs), a data segment (ds), a stack segment (ss), and an additional segment (s). Each segment is 64 kb, but they can access the same memory area or overlap sides.

A nearest pointer is a 16-bit pointer inside the same segment. It is used as a pointer to data or code in the same module.

A far pointer is a 16 + 16-bit pointer consisting of a 16-bit segment offset and the nearest pointer. It is used as a pointer to data or code in another module. When you use the far pointer to call a procedure, part of the segment is placed in the cs and ds (IIRC) registers to access the code and data in this module.

The physical address of the segment + pointer pair is calculated as the segment pointer * 16+. This means that a 16-bit program can receive 1024 kbytes of memory. To access more memory, two extended and extended memory methods are used. (Also, to some extent, the high memory method, where the address did not wrap around the 1 MB barrier but using the FFFF segment offset, will give you direct access to 65520 bytes of extended memory.)

+8
source

He can come back. I heard the murmur of a tendency to look at PAE with all these x64 processors floating around. Thus, the program can address a normal memory limit of 2 or 3 gigabytes (depending on the OS boot settings), but it has a 48-bit pointer that can address another 4 gigabytes. Of course, you should have a lot of cheap physical DDR3 memory. Say 24 gig. Not too many programs that require more than 3 gigabytes. Swap file sharing means that not all of your running program is in memory anyway. But perhaps this is data for scanning or processing.

So far can return as a 48-bit pointer to help navigate from the address of the 32- to 64-bit address.

+1
source

All Articles