home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR13 / TI_BC1.ZIP / TI1563.ZIP / TI1563.ASC
Text File  |  1993-10-05  |  4KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1563
  9.   VERSION  :  3.x
  10.        OS  :  All
  11.      DATE  :  October 5, 1993                          PAGE  :  1/3
  12.  
  13.     TITLE  :  Allocating data >64K with the keyword huge
  14.  
  15.  
  16.  
  17.  
  18.   The segmented architecture of the 80x86 processor is not well-
  19.   suited for data structures that are of a size equal to or greater
  20.   than 64K, more precisely 65536 bytes.  To ease the programing
  21.   difficulties caused by this limitation of the processor, Borland
  22.   has implemented the "huge" keyword in association with pointers.
  23.  
  24.  
  25.   Dynamic Allocation
  26.   ------------------
  27.  
  28.      The typical syntax for dynamic allocation in C is
  29.  
  30.          char huge *BigArray = (char huge *) farmalloc(120000L);
  31.          char huge *BigArray = (char huge *) farcalloc(120000L);
  32.  
  33.      Similarly, the huge keyword can be used with new in C++:
  34.  
  35.          char huge *BigArray = new huge char[120000];
  36.  
  37.  
  38.   Static Allocation
  39.   -----------------
  40.  
  41.          In DOS, these data structures can also be allocated
  42.      statically in the DGROUP.  For example,
  43.  
  44.          char huge BigArray[120000L];
  45.  
  46.          int main(void)
  47.          {
  48.              return 1;
  49.          }
  50.  
  51.      Because the huge keyword implies a data structure greater than
  52.      64K and the stack is limited to 64K, you cannot allocate a
  53.      huge data structure locally unless it is declared static.
  54.      Remember that static local variables are placed in the data
  55.      segment, not on the stack. For example:
  56.  
  57.          int main(void)
  58.          {
  59.              char huge BigArray[120000L];        // ERROR!!!
  60.              static char huge BigArray[120000L]; // LEGAL
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1563
  75.   VERSION  :  3.x
  76.        OS  :  All
  77.      DATE  :  October 5, 1993                          PAGE  :  2/3
  78.  
  79.     TITLE  :  Allocating data >64K with the keyword huge
  80.  
  81.  
  82.  
  83.  
  84.              return 1;
  85.          }
  86.  
  87.      Because of complications produced by the Windows' loader,
  88.      static allocation of huge data structures is not supported in
  89.      Windows.
  90.  
  91.  
  92.   Memory Models
  93.   -------------
  94.  
  95.      Huge data structures can be allocated dynamically in all
  96.      memory models except for tiny.  However this implies that the
  97.      data is far ( i.e. is in a segment other than DS ).  For the
  98.      small and medium memory models in DOS, your application must
  99.      use functions that assume far data when manipulating the
  100.      elements of the structure.  Also, you must use the far keyword
  101.      in your class declaration in these two memory models in DOS.
  102.      This also applies to Windows.
  103.  
  104.      Note that the huge memory model does _NOT_ imply huge
  105.      pointers.
  106.  
  107.  
  108.   Element Size
  109.   ------------
  110.  
  111.      The elements of the huge array must have a size that is a
  112.      power of 2 ( i.e. 2, 4, 8, 16, 32, etc. ).  This ensures that
  113.      no individual element overlaps a segment boundary.  Though the
  114.      compiler can handle element access of arrays greater than 64K,
  115.      the code generated cannot deal with the case of an array
  116.      element that straddles a segment boundary.
  117.  
  118.  
  119.   Multi-dimensional Arrays
  120.   ------------------------
  121.  
  122.      The syntax for declaring a multi-dimensional array is the same
  123.      as that of a single dimension array if no dimension of the
  124.      array by itself requires greater than 64K.  For example,
  125.  
  126.          unsigned (huge *Array2)[100] =
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1563
  141.   VERSION  :  3.x
  142.        OS  :  All
  143.      DATE  :  October 5, 1993                          PAGE  :  3/3
  144.  
  145.     TITLE  :  Allocating data >64K with the keyword huge
  146.  
  147.  
  148.  
  149.  
  150.            new huge unsigned[1000][100];
  151.  
  152.      Complications arise dynamically allocating multi-dimensional
  153.      arrays with new if any one dimension of the array is itself
  154.      greater than 64K.  For example,
  155.  
  156.          unsigned huge (huge *Array4)[40000L] =
  157.            new huge huge unsigned[4][40000L];
  158.  
  159.      Syntax for static allocation is the same as the syntax for
  160.      single dimension arrays.
  161.  
  162.  
  163.   DISCLAIMER: You have the right to use this technical information
  164.   subject to the terms of the No-Nonsense License Statement that
  165.   you received with the Borland product to which this information
  166.   pertains.
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.