远指针和近指针有什么区别

远指针和近指针有什么区别

本文介绍了远指针和近指针有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我C中far指针和near指针的区别?

Can anybody tell me the difference between far pointers and near pointers in C?

推荐答案

在 16 位 x86 分段内存架构上,使用四个寄存器来引用各自的段:

On a 16-bit x86 segmented memory architecture, four registers are used to refer to the respective segments:

  • DS → 数据段
  • CS → 代码段
  • SS → 堆栈段
  • ES → 额外片段

这个架构上的逻辑地址写成segment:offset.现在回答问题:

A logical address on this architecture is written segment:offset. Now to answer the question:

  • 近指针引用(作为偏移量)当前段.

  • Near pointers refer (as an offset) to the current segment.

远指针使用段信息和偏移量来指向段.因此,要使用它们,必须将 DS 或 CS 更改为指定值,内存将被取消引用,然后恢复 DS/CS 的原始值.请注意,对它们的指针运算不会修改指针的段部分,因此溢出的偏移量只会将其环绕.

Far pointers use segment info and an offset to point across segments. So, to use them, DS or CS must be changed to the specified value, the memory will be dereferenced and then the original value of DS/CS restored. Note that pointer arithmetic on them doesn't modify the segment portion of the pointer, so overflowing the offset will just wrap it around.

然后是巨大的指针,它们被标准化为具有给定地址的最高可能段(与远指针相反).

And then there are huge pointers, which are normalized to have the highest possible segment for a given address (contrary to far pointers).

在 32 位和 64 位架构上,内存模型使用不同的段,或者根本不使用.

On 32-bit and 64-bit architectures, memory models are using segments differently, or not at all.

这篇关于远指针和近指针有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 23:34