Archived

This topic is now archived and is closed to further replies.

FrancoisSoft

Tell me about the "FAR" pointer.

Recommended Posts

What us the FAR pointer? Does it mean that the pointer points to any memory on the computer? In other words does a FAR pointer get you out of local or protected memory and allow you to access any memory you want? I''ve done some research on this but I didn''t get the information I was looking for. Here''s what I''m talking about... char FAR *Pointer; Hey, don''t forget to visit my page... by clicking here!

Share this post


Link to post
Share on other sites
Near and far pointers as they relate to x86 ASM programming:

A near pointer is a 16 bit value that provides an offset into a segment. It could be any segment but you will generally use the data segment. Unfortunately, they have one very serious drawback - you can only access 64K of data (one segment) when using near pointers. Far pointers overcome this limitation at the expense of being 32 bits long*. However, far pointers let you access any piece of data anywhere in the memory space.

*I'm not so sure this is really precisely true. Like Meldroc said, a far pointer may occupy two 16-bit registers, but the segment:offset model overlaps the two registers, producing a 20-bit address capable of addressing about a meg, as someone else mentioned

Later,
ZE.

edit : grammar!

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links


[edited by - zealouselixir on September 3, 2003 6:25:17 PM]

[edited by - zealouselixir on September 3, 2003 6:29:50 PM]

Share this post


Link to post
Share on other sites
AFAIK, far pointers are used with systems with segmented memory architectures - like 16-bit x86 in MS-DOS. In DOS, since the processor was in 16-bit real mode, its 16-bit registers couldn''t address more than 64Kb of memory, so they used two registers for an address. The address is composed of a segment value and an offset value. The segment address is left-shifted by four bits, then the offset was added so a DOS machine could address up to 1 meg of RAM (of course, only 640Kb was available to the user, the top 384Kb was reserved for other things - expanded memory, video buffers for the VGA card, etc.)

When making programs in MS-DOS, you use different memory models. The simplest, the tiny memory model, all had to fit in one segment, meaning your program, data & stack could not be bigger than 64K. Most MS-DOS programs used a memory model where the program code was in one segment, the most common data was in another segment, and the stack was in a third segment (or shared a segment with data.) If your program or data is larger than sixty four KB, you had to locate them in another segment, thus requiring more memory addressing voodoo.

Basically, a far pointer is a pointer to a memory address in an arbitrary segment. The opposite, a near pointer, is only an offset to an address in the default segment.

I probably got some details wrong, but hopefully some of this makes sense. In any case, if you''re using a modern 32-bit system, you shouldn''t have to worry about segmented addressing or far pointers - 32-bit addresses can handle up to 4Gb, and at the moment, most people don''t need to address more memory than that.

Share this post


Link to post
Share on other sites