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

ID: Q133067


The information in this article applies to:


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:

Q102391 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          : kbcode kb16bitonly kbCompiler kbCPPonly kbLangCPP kbVC 
Version           : WINDOWS:1.0,1.5,1.51,1.52
Platform          : 
Issue type        : kbhowto 

Last Reviewed: July 21, 1999