home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / arrays / xarray / xarray.h < prev   
Encoding:
C/C++ Source or Header  |  1992-07-11  |  4.2 KB  |  127 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. #define XARRAY(type) class x##type { private: long *offset; int *block;\
  72.     char xorxx; char temp; long xxind;\
  73.     public: x##type() {temp = 1;}; x##type (long size) {construct (size);} \
  74.     void construct (long size) {temp = 0; \
  75.     long y=size/256; if ((size%256)>0) y++;\
  76.     create_xms_array (y,256,sizeof(type), &offset, &block); xorxx=1; } \
  77.     x##type (const x##type& x) { \
  78.     offset=x.offset; block=x.block, xorxx=x.xorxx; xxind=x.xxind; temp=1;}\
  79.     void destroy() { if (!temp) delete_xms_array (&offset, &block);} \
  80.     ~x##type() { destroy();} \
  81.     type##& operator[](long index) { long ind= index>>8; \
  82.     if (xorxx) return *( type *)\
  83.     (large_array(block[ind],offset[ind]+((index&255)*sizeof(type))));\
  84.     return *( type *)\
  85.     (large_array(block[xxind],offset[xxind]+(index*sizeof(type))));}\
  86.     friend class xx##type;\
  87.     };
  88.  
  89. #define XXARRAY(type)\
  90. class xx##type { \
  91.     private :\
  92.     x##type normal; \
  93.     public: \
  94.     xx##type () {normal.temp=1;}; \
  95.     xx##type (long x, long y) { construct (x,y);} \
  96.     xx##type (const xx##type& x) { \
  97.     normal=x.normal; \
  98.     normal.temp=1; } \
  99.     void construct (long x, long y) \
  100.     { create_xms_array (x,y,sizeof(type), &normal.offset, &normal.block);\
  101.     normal.xorxx=0; normal.temp=0;}\
  102.     void destroy() { normal.destroy();} \
  103.     ~xx##type() { destroy();} \
  104.     x##type##& operator[](long index) { \
  105.     normal.xxind=index; \
  106.     return /*( x##type *)*/normal; } };
  107.  
  108. #define FXXARRAY(type) class fxx##type { private : long *offset; int *block;\
  109.     public: fxx##type () {;}; fxx##type (long x, long y) \
  110.     { construct (x,y);} void construct (long x, long y) \
  111.     { create_xms_array (x,y,sizeof(type), &offset, &block); }\
  112.     type##* operator[](long index) { \
  113.     return ( type *)(large_array(block[index],offset[index])); } };
  114.  
  115.  
  116. XARRAY (float)
  117. XXARRAY (float)
  118. XARRAY (double)
  119. XXARRAY (double)
  120. XARRAY (int)
  121. XXARRAY (int)
  122. XARRAY (char)
  123. XXARRAY (char)
  124.  
  125.  
  126. #endif
  127.