home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / cpluspls / vir_v203.zip / TXARRAY.H < prev    next >
C/C++ Source or Header  |  1992-07-11  |  4KB  |  141 lines

  1. #ifndef __VIRIMG_H
  2. #define __VIRIMG_H
  3.  
  4.  
  5. #define XDISK 1
  6. #define XXMS 2
  7.  
  8.  
  9. /*  This file contains a two macros for creating extedend arrays and defines
  10.     the following extended array types
  11.     xdouble, xfloat, xint, xchar
  12.     xxdouble, xxfloat, xxint, xxchar
  13.  
  14.     A variable x of type xx<type> will return a variable
  15.     of type x<type> from x[<index>]
  16. */
  17.  
  18. /* The following are various external parameters for the Virtual Arrays
  19.     all have defaults which are shown as the first in the list */
  20. /* Do you want to keep Extended memory safe : 1=Yes 0=No */
  21. extern char ___safety;
  22. /* What is the file used for keeping extended memory safe : c:\!safety!.xms
  23. extern char *___safe_filename;
  24. /* Do you want informative messages from the array manager : 1=Yes 0=No */
  25. extern char ___msgs;
  26. /* What is the filename for the disk caching manger swap file : virarray.swp*/
  27. extern char *___xfilename;
  28. /* What is the size of the file buffer for the disk manager : 32768*/
  29. extern int ___xfile_buf;
  30. /* Where are the CPP arrays to be cached : XXMS = Extended memory
  31.                                            XDISK = Disk */
  32. extern char ___xarrays;
  33. /* How many blocks are to be held in coventional memory for CPP arrays : 4*/
  34. extern int __mem_buf;
  35. /* What is the block size for the CPP manager : 32768 */
  36. extern long __block_size;
  37. /* How many block does the CPP manager want : 16 */
  38. extern int __blocks;
  39. /* If there is not enough Xtended memory should the manger cache to disk
  40.         instead : 1=Yes 0=No */
  41. extern char ___auto_disk;
  42.  
  43. /* The main variables for XARRAY.H are
  44.     __mem_buf, __block_size and __blocks
  45.  
  46.     __mem_buf         is the number of memory block in conventional memory
  47.     __block_size     is the size of the cache block
  48.     __blocks         is the total number of block needed
  49.                     __block is restricted to 16 in the demo version
  50.  
  51.     The conventional memory used is __mem_buf*__block_size
  52.     The cache memory used is         __blocks*__block_size
  53.  
  54.     By juggling these values around you can trade off speed with memory used
  55. */
  56.  
  57.  
  58. extern "C" {
  59. void initialise_virtual_arrays(int real_img,long array_size,unsigned int no_imgs, int dorx);
  60. void *pointer_add(void *tes,long no);
  61. void *large_array(int no,long ind);
  62. void *img(int no);
  63. void create_xms_array (long x, long y, int size, long **offset, int **block);
  64. void delete_xms_array (long **offset, int **block);
  65.  
  66. /*Timer to measure the time taken for sections of code */
  67. void start_timer();
  68. void stop_timer();
  69. }
  70.  
  71. template <class T>
  72. class xarray
  73. {
  74. public:
  75. //private:
  76.     long *offset; int *block;
  77.     char xorxx; char temp; long xxind;
  78. public:
  79.     xarray() {temp = 1;};
  80.     xarray (long size) {construct (size);}
  81.     void construct (long size)
  82.     {
  83.         temp = 0;
  84.         long y=size/256;
  85.         if ((size%256)>0) y++;
  86.         create_xms_array (y,256,sizeof(T), &offset, &block);
  87.         xorxx=1;
  88.     }
  89.     xarray (const xarray<T>& x)
  90.     {
  91.         offset=x.offset;
  92.         block=x.block;
  93.         xorxx=x.xorxx;
  94.         xxind=x.xxind;
  95.         temp=1;
  96.     }
  97.     void destroy()
  98.     {
  99.         if (!temp) delete_xms_array (&offset, &block);
  100.     }
  101.     ~xarray() { destroy();}
  102.     T& operator[](long index)
  103.     {
  104.         long ind= index>>8;
  105.         if (xorxx) return *( T *)(large_array(block[ind],offset[ind]+((index&255)*sizeof(T))));
  106.         return *( T *)(large_array(block[xxind],offset[xxind]+(index*sizeof(T))));
  107.     }
  108. //    friend class xxarray<T>;
  109. };
  110.  
  111. template <class T>
  112. class xxarray
  113. {
  114. private :
  115.     xarray<T> normal;
  116. public:
  117.     xxarray () {normal.temp=1;};
  118.     xxarray (long x, long y) { construct (x,y);}
  119.     xxarray (const xxarray<T>& x)
  120.     {
  121.         normal=x.normal;
  122.         normal.temp=1;
  123.     }
  124.     void construct (long x, long y)
  125.     {
  126.         create_xms_array (x,y,sizeof(T), &normal.offset, &normal.block);
  127.         normal.xorxx=0;
  128.         normal.temp=0;
  129.     }
  130.     void destroy() { normal.destroy();}
  131.     ~xxarray() { destroy();}
  132.     xarray<T>& operator[](long index)
  133.     {
  134.         normal.xxind=index;
  135.         return normal;
  136.     }
  137. };
  138.  
  139.  
  140. #endif
  141.