Using Huge Pointers with Blocks of Memory Larger Than 64K

Last reviewed: July 23, 1997
Article ID: Q79194
3.00 3.10 WINDOWS kbprg

The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

SUMMARY

The GlobalAlloc() function can be used to allocate memory blocks larger than 64 kilobytes (64K). This memory can then be accessed using "huge" pointers. For more information on huge pointers, see your Microsoft C compiler documentation.

MORE INFORMATION

GlobalAlloc() always returns a single contiguous block of memory, if it is possible to satisfy the request. This block can be accessed using huge pointers. Huge pointers are composed of a segment:offset address (real mode), or a selector:offset address (standard mode or 386 enhanced mode), just like a far pointer. Huge pointers allow access to more than 64K, by adjusting the segment or selector part of the address, as well as the offset.

In real mode, the segment address increases or decreases by 0x1000 every time the offset crosses the 64K boundary. In standard mode or 386 enhanced mode, memory is addressed using selectors instead of segments. When GlobalAlloc() allocates a block of memory, it also creates selectors to access that block. If the block of memory is larger than 64K, GlobalAlloc() will create a set of tiled selectors. The first selector in the set provides access to the first 64K of the block. Subsequent selectors provide access to additional 64K portions of the memory block.

Tiled selectors are allocated in a predefined pattern; the value of the second selector equals the value of the first selector plus the value of __AHINCR, and so forth. Therefore, when the offset of a huge pointer crosses a 64K boundary in standard mode or 386 enhanced mode, the value of the selector is increased or decreased by the value of __AHINCR.


Additional reference words: 3.00 3.10
KBCategory: kbprg
KBSubcategory: KrMm
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 23, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.