Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
151 views
in Technique[技术] by (71.8m points)

c++ - What is a long pointer?

I am reading a book and it mentions certain data type as being long pointer. Just curious about what that meant. Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Some processors have two types of pointers, a near pointer and a far pointer. The near pointer is narrower (thus has a limited range) than a far pointer. A far pointer may also be a long pointer.

Some processors offer relative addressing for things nearby. A long pointer may indicate that the item is not close by and relative addressing cannot be used.

In any case, long pointers are a platform specific issue and may not be portable to other OSes or platforms.

Edit: (further explanation and usage of relative addressing)

Address distances are less of a high level concept and more of an assembly language concept. The distance is measured from the program counter (either the current address or the next address) and the start of the object (function or data). If the location is greater than the limit for a small, relative pointer, a longer pointer will be necessary.

Example: Given a system with 32 bit "long" addressing and 8-bit relative addressing. The relative distance would allow for at least 127 bytes in the forward (positive value) or previous (negative) direction. If the target is 1024 bytes away, a full 32-bit pointer must be used.

This is an optimization feature based on the concept that most instructions and data are near by. The majority of loops have a small distance between the start of the loop and end of the loop. These employ relative addressing for execution.

Most data is nearby, whether a data constant or a variable. In more detail, the data is near a frame or reference point. Local variables are placed on the stack, relative to a frame or base address. This base address is the start of the stack before the function is executed. Thus the data can be accessed using addressing relative to the stack frame start.

The processors allow compilers to use specialized instructions for relative (near) addressing. On many processors, the instructions to use relative addressing are smaller than instructions using long address. Thus the processor requires less fetching from the instruction cache and the instruction cache can hold more instructions.

Long and short, near and far, addressing may depend on the scope of the data or function. There are other factors involved, such a PIC (position indepent code), virtual memory and paging.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...