INFO: Multiple Instance Large Model Windows MFC ApplicationsID: Q85736
|
In the small and medium memory models, all objects based on the Microsoft
Foundation Class library must be placed in the near heap. This imposes a
limit on the number of objects that can be allocated because the near heap
is typically less than 64K in size. The Microsoft Foundation Class library
does not allow a small or medium model application to create a far instance
of any of the standard classes from the Microsoft Foundation Class library.
To create far instances of classes based on the Microsoft Foundation Class
library, the compact or large memory model must be used.
This article discusses some of the issues regarding large memory model
Microsoft Windows-based applications built with the Microsoft Foundation
Class library.
Member functions of classes are called with an implicit "this" pointer, which points to the data for the class. By default, the size of the this pointer is determined by the ambient memory model. For small and medium models, the this pointer is near. For large, compact, and huge models, the this pointer is far. For example, consider the following line of code in a medium memory model application:
lpMyString = new FAR CString;
The pointer to the new object will be a far pointer. However, the member
functions of the class CString in the medium memory model Microsoft
Foundation Class library expect a near this pointer. As a result, the
compiler will generate a C2662 error stating that it cannot convert the
this pointer from far to near. For more information on the this pointer and
how it is affected by different memory models, please refer to the on-line
help for the __far keyword.
NMAKE MODEL=L TARGET=W OPT=/Gx
NOTE: The /Gx option does not work for static or global objects. These
objects must be explicitly declared as NEAR in order for them to be placed
in DGROUP. For example, in the HELLO.CPP sample Microsoft Foundation Class
Windows-based application, the following code used to create the
application object
CTheApp theApp;
should be changed to the following:
CTheApp NEAR theApp;
Additional query words:
Keywords : kb16bitonly kbnokeyword kbMFC kbVC
Version : 1.0 1.5 1.51 1.52 7.0
Platform :
Issue type : kbinfo
Last Reviewed: July 30, 1999