PRODUCT : Borland C++ NUMBER : 1563 VERSION : 3.x OS : All DATE : October 25, 1993 PAGE : 1/3 TITLE : Allocating data >64K with the keyword huge The segmented architecture of the 80x86 processor is not well- suited for data structures that are of a size equal to or greater than 64K, more precisely 65536 bytes. To ease the programing difficulties caused by this limitation of the processor, Borland has implemented the "huge" keyword in association with pointers. Dynamic Allocation ------------------ The typical syntax for dynamic allocation in C is char huge *BigArray = (char huge *) farmalloc(120000L); char huge *BigArray = (char huge *) farcalloc(120000L); Similarly, the huge keyword can be used with new in C++: char huge *BigArray = new huge char[120000]; Static Allocation ----------------- In DOS, these data structures can also be allocated statically in the DGROUP. For example, char huge BigArray[120000L]; int main(void) { return 1; } Because the huge keyword implies a data structure greater than 64K and the stack is limited to 64K, you cannot allocate a huge data structure locally unless it is declared static. Remember that static local variables are placed in the data segment, not on the stack. For example: int main(void) { char huge BigArray[120000L]; // ERROR!!! static char huge BigArray[120000L]; // LEGAL PRODUCT : Borland C++ NUMBER : 1563 VERSION : 3.x OS : All DATE : October 25, 1993 PAGE : 2/3 TITLE : Allocating data >64K with the keyword huge return 1; } Because of complications produced by the Windows' loader, static allocation of huge data structures is not supported in Windows. Memory Models ------------- Huge data structures can be allocated dynamically in all memory models except for tiny. However this implies that the data is far ( i.e. is in a segment other than DS ). For the small and medium memory models in DOS, your application must use functions that assume far data when manipulating the elements of the structure. Also, you must use the far keyword in your class declaration in these two memory models in DOS. This also applies to Windows. Note that the huge memory model does _NOT_ imply huge pointers. Element Size ------------ The elements of the huge array must have a size that is a power of 2 ( i.e. 2, 4, 8, 16, 32, etc. ). This ensures that no individual element overlaps a segment boundary. Though the compiler can handle element access of arrays greater than 64K, the code generated cannot deal with the case of an array element that straddles a segment boundary. Multi-dimensional Arrays ------------------------ The syntax for declaring a multi-dimensional array is the same as that of a single dimension array if no dimension of the array by itself requires greater than 64K. For example, unsigned (huge *Array2)[100] = PRODUCT : Borland C++ NUMBER : 1563 VERSION : 3.x OS : All DATE : October 25, 1993 PAGE : 3/3 TITLE : Allocating data >64K with the keyword huge new huge unsigned[1000][100]; Complications arise dynamically allocating multi-dimensional arrays with new if any one dimension of the array is itself greater than 64K. For example, unsigned huge (huge *Array4)[40000L] = new huge huge unsigned[4][40000L]; Syntax for static allocation is the same as the syntax for single dimension arrays. DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.