Near and Far pointers

前端 未结 2 914
醉话见心
醉话见心 2020-11-28 10:40

What is difference between our usual pointers(ones which we normally use), near pointers and far pointers and is there a practical usage for near and far pointers in present

相关标签:
2条回答
  • 2020-11-28 10:50

    The near and far keywords have their origin in the segmented memory model that Intel had before. The near pointers could only access a block of memory originally around 64Kb in size called a segment whereas the far pointers could go outside of that range consisting of a segment and offset in that segment. The near pointers were much faster than far pointers so therefore in some contexts it paid off to use them.

    Nowadays with virtual memory near and far pointers have no use.

    EDIT:Sorry if I am not using the correct terms, but this is how I remembered it when I was working with it back in the day :-)

    0 讨论(0)
  • 2020-11-28 11:10

    Near and far is spoken in the context of machine architecture (x86, x64, 640kb + model of memory, x32 in mean of the protected mode and segmented, x86 in terms of segmented memory)

    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.

    Nowadays only x86 x32 addressing - a long pointer and x64 64 bit addressing are having and taking (permanent) place. Yes, a x64 in windows is compiled by MS VC the way it "sees" still like x86 x32 application ONLY 4Gb of memory. So you do not know by the default the difference between near and far or some other addressation. BUT x64 target has the ability to address the memory using the other, long long type of pointer.

    As you see there is no practical scenario in MS VC if you do not "see" the variant of the x64 addressing over x32 in the different pointers. Just a hypotetics.

    Staying away from this practical uses are LP_STRING - long pointer towards the string and INT_PTR - integer holding a value of pointer.

    First you must understand, that CPU and compiler accepts the set of pointers-to-use sizes. And only them. You can't find a way round them without additional compilers/linkers/hardware. INT_PTR - is just for storage of the pointers that does not exceed int in length (a value of pointer, where pointer length is not greater than int). and LP_STRING - is just long type of pointer of the compiler/processor (they both like abstractions and compiler is not equal in the behaviour to the compiler, as well as x64 can be Intel rarely used one and widely used AMD).

    ANY size of variable can be a pointer.

    You just need a practical example against AMD x64 and LLP (long long pointer).

    0 讨论(0)
提交回复
热议问题