Allocating Space in the Far Heap in Near Data Models

Last reviewed: July 17, 1997
Article ID: Q87637
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbprg

The information in this article applies to:

  • Microsoft C/C++ compiler for MS-DOS, version 7.0
  • Microsoft Visual C++ for Windows, versions 1.0 and 1.5

SUMMARY

To force an object to be allocated in the far heap in a small or medium memory model C++ program, use the __far keyword in front of the object being allocated.

For example, where T is either an implicit or user-defined type, the syntax would be:

   new __far T;

This returns a far pointer to an object of type T allocated in the far heap. However, if type T is a near class, the following error will be generated:

   C2512: no appropriate default constructor available

This error is generated because the far pointer cannot be converted to a near pointer when the constructor is invoked.

The programmer must then declare the class as a far class or provide a special constructor that takes a far "this" pointer.


Additional reference words: kbinf 7.00 1.00 1.50
KBCategory: kbprg
KBSubcategory: CPPLngIss
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 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.