Use Huge Pointers if Data Item Is Larger than 64KLast reviewed: July 17, 1997Article ID: Q41247 |
6.00 6.00a 6.00ax 7.00 | 6.00 6.00a | 1.00 1.50
MS-DOS | OS/2 | WINDOWSkbprg The information in this article applies to:
SUMMARYThere are three types of data pointers in Microsoft C: near, far, and huge. Near pointers represent offsets within DGROUP (the default data segment) and are stored in 2 bytes. Far and huge pointers contain both a segment address/selector and an offset, and therefore take 4 bytes. However, the arithmetic done on far and huge pointers is different. Therefore, huge pointers should be used for an item that will cross a segment boundary.
MORE INFORMATIONAlthough far and huge pointers are identical in format, the algorithms used to do addressing calculations involving these pointers are very different. Far pointers are assumed to point to a data item that does not cross a segment boundary (in other words, the size of the item must be less than 64K). As a result, the compiler ignores the segment part of the pointer in all calculations except for "equals" and "not equals" tests. This gives a considerable savings in execution time (more than twice as fast) for these operations. In fact, calculations involving far pointers are almost as fast as calculations involving near pointers. Huge pointers may point to items that are larger than 64K. The addressing arithmetic works on both the segment and the offset. Huge pointer arithmetic is therefore considerably slower than far arithmetic, but it has the advantage of working when the data item is larger than 64K. When compiling with the huge memory model (/AH), all pointers are huge pointers. If there are only a few items that need huge pointers, it would be better to use a large memory model and explicitly declare those items huge; otherwise, there is a considerable performance hit. Use one of the following methods to declare an array of 75,000 chars:
Huge pointer arithmetic is not supported in the small and medium model run-time libraries. In the compact and large model libraries, only the following functions support huge pointer arithmetic:
bsearch _fmemchr _fmemmove lfind fread _fmemcmp _fmemset lsearch fwrite _fmemcpy halloc memccpy _fmemccpy _fmemicmp hfree memchrNOTE: The count parameter of many of these functions is of type size_t, which is an unsigned int (65535). Although these functions can accept huge pointers to objects in which the area being copied from and to can span a segment boundary, the function still only supports copying 64K worth of data at a time.
|
Additional reference words: kbinf 1.00 1.50 6.00 6.00a 6.00ax 7.00 8.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |