//This program demonstrates allocating greater than 64k of memory in a //16-bit Windows application. To accomplish this, we must do 3 things. // // 1. Use a huge pointers. // 2. Allocate the memory on the heap, not in the automatic data segment. // Specifically, we must use 'new' and not try to allocate data // globally or even locally in a function. // 3. Make the size of the elements of the memory block a power of 2. // Otherwise, an element of the memory block will stradle the 64k // segment boundaries, and the huge pointer, when incremented across // those boundaries, will not subsequently point to the beginning of // and element. // // Confused? Want more info? "Windows Programmer's guide to DLLs and // Memory Management" by Mike Klein, Sams Publishing 1994. // //Compile using the following command, // // bcc -v -ml -tWE thisfile.cpp // //George Cross, Borland C++ Developer Support, October 1996 #define STRICT #define __TRACE #include #include int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { struct data{ char ate[11]; long mins; int secs; int tenths; long calls; char dte[9]; char padding[12]; }; data huge* darray = new huge data[4611]; for (int i=0; i<4611; i++){ darray[i].mins = 0; if (i == 4000) TRACE("Loop has passed " << i << " times already."); } return 0; }