ID: Q45705
5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a | 1.00 1.50
MS-DOS                      | OS/2            | WINDOWS
The information in this article applies to:
    - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax
    - Microsoft C for OS/2, versions 5.1, 6.0, and 6.0a
    - Microsoft C/C++ for MS-DOS, versions 7.0
    - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
In Microsoft C , halloc() and huge arrays are limited to allocating 128K unless the size of the elements is a power of 2.
With huge pointers and arrays, the Microsoft C Compiler produces 32- bit pointer arithmetic only when accessing whole elements. Only the 16-bit offset of a pointer is used when accessing the individual members of elements. This technique is used in the interest of speed and smaller code size. However, it assumes that elements do not extend from the end of one segment into the beginning of the next. When crossing a 64K segment boundary, elements must end evenly with the end of that segment. The following diagram illustrates the conditions necessary for huge pointers and arrays:
                             Seg1 Seg2
     Segment 1               FFFF 0000               Segment 2
     ----------------------------+----------------------------
    ......| Elem | Elem  | Elem  + Elem  | Elem  | Elem  |.....
    ......| X     | X+1  | X+2   + X+3   | X+4   | X+5   |.....
     ----------------------------+----------------------------
                                 ^ Elements must not cross
                                   a segment boundary.
If the allocated elements do not fit evenly into a segment, there can be only one segment boundary onto which they fall evenly. The function halloc() uses the element size it is passed to calculate and return a pointer with an offset that results in the allocated elements falling evenly on this boundary. The following diagram demonstrates the way this is done and what can happen at the end of the second segment:
        Segment 1                     Segment 2
        0000           FFFF 0000           FFFF
     +----------------------+-------------------+
     +Pad |Elem |Elem |Elem +Elem |Elem |Elem | +
     +----------------------+-------------------+
      ^   ^                                   ^
      ^   ^                                   Next element won't fall
      ^   ^                                   on segment bounds.
      ^   ^
      ^   Offset returned to allow elements to fall on segment bounds.
      ^
      Padding area used to force element boundary to fall on segment
      boundary.
Additional reference words: kbinf 5.10 6.00 6.00a 6.00ax 7.00 1.00 1.50 64K KBCategory: kbprg KBSubcategory: CRTIss Keywords : kb16bitonly
Last Reviewed: July 18, 1997