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

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.


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
Issue type : kbhowto
Technology : kbVCsearch kbAudDeveloper kbCVCComp


Last Reviewed: May 8, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.