What are near, far and huge pointers?

前端 未结 6 1052
刺人心
刺人心 2020-11-30 01:34

Can anyone explain to me these pointers with a suitable example ... and when these pointers are used?

6条回答
  •  抹茶落季
    2020-11-30 01:56

    This terminology was used in 16 bit architectures.

    In 16 bit systems, data was partitioned into 64Kb segments. Each loadable module (program file, dynamically loaded library etc) had an associated data segment - which could store up to 64Kb of data only.

    A NEAR pointer was a pointer with 16 bit storage, and referred to data (only) in the current modules data segment.

    16bit programs that had more than 64Kb of data as a requirement could access special allocators that would return a FAR pointer - which was a data segment id in the upper 16 bits, and a pointer into that data segment, in the lower 16 bits.

    Yet larger programs would want to deal with more than 64Kb of contiguous data. A HUGE pointer looks exactly like a far pointer - it has 32bit storage - but the allocator has taken care to arrange a range of data segments, with consecutive IDs, so that by simply incrementing the data segment selector the next 64Kb chunk of data can be reached.

    The underlying C and C++ language standards never really recognized these concepts officially in their memory models - all pointers in a C or C++ program are supposed to be the same size. So the NEAR, FAR and HUGE attributes were extensions provided by the various compiler vendors.

提交回复
热议问题