HOWTO: Create Two-dimensional Huge Arrays w/ C++ new Operator

Last reviewed: August 26, 1997
Article ID: Q133067
The information to this article applies to:
  • The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, 1.52

SUMMARY

The code sample in this article shows two ways to dynamically create huge two-dimensional arrays (bigger than the 64K byte limit) using the C++ new operator. One method shows the proper use of the __huge keyword for 16-bit compilers.

For more information on creating a two-dimensional array (with a size less than 64K bytes), please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q102391
   TITLE     : HOWTO: Create Two-Dimensional Arrays with Operator new

MORE INFORMATION

Here are two methods you can use to create a large two-dimensional array. The first method, for the 16-bit compiler, shows the proper use of the __huge keyword. The second method needs a special compiler option for a 16-bit Windows-based application.

First Method Sample Code

A pointer to an array of the elements to be created is to be declared First as follows:

   /* For 16-bit compiler  */
   /* No special compile options needed. */

   #include <iostream.h>

   void main(void)
   {
       char (__huge *varchar)[350];            // Declare pointer to an
                                               // array of 350 characters.
       varchar = new __huge char[130000][350]; // Pointer declaration and
                                               // the initialization have
                                               // to be on separate lines.
       /* Application code */

       delete [] varchar;
   }

Second Method Sample Code

   /* Use the Huge memory model compiler option with the 16-bit compiler */

   void main(void)
   {
      char (*varchar )[350];
      varchar = new char [130000][350];

      /* Application code */

      delete [] varchar;
   }

The second method can be used in Visual C++ versions 2.0 and 2.1 without using any compiler option.


Additional query words: 8.0 8.0c 8.00 8.00c
Keywords : CPPIss CPPLangIss kb16bitonly kbcode
Version : WINDOWS:1.0,1.5,1.51,1.52
Issue type : kbhowto


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: August 26, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.