home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / progjour / 1990 / 05 / vtestc.c < prev    next >
Text File  |  1990-08-03  |  1KB  |  51 lines

  1. #include <stdio.h>
  2. #include "virt.h"
  3.  
  4. main ()
  5. {
  6.         void *handle;
  7.         long x;
  8.         long *p;
  9.         
  10.         vopen();
  11.         
  12.         /* allocate a 100,000-element array of longs */
  13.         
  14.         if ( !(handle = vmalloc(100000L, sizeof(long)) ) )
  15.             perror("vmalloc()");
  16.                                 
  17.         /* assign array[10] and array[99,999] to 0 */
  18.  
  19.         x = *(long *)vread(handle, 10L);
  20.         x = 0;
  21.         vwrite(handle, 10L, &x);
  22.  
  23.         x = *(long *)vread(handle, 99999L);
  24.         x = 0;
  25.         vwrite(handle, 99999L, &x);
  26.  
  27.         /* add 5 to array[10] */
  28.  
  29.         x = *(long *)vread(handle, 10L);
  30.         x += 5;
  31.         vwrite(handle, 10L, &x);
  32.         
  33.         /* add 5 to array[99999] using the faster method */
  34.  
  35.         p = (long *)vread(handle, 99999L);
  36.         *p += 5;
  37.         vdirty(handle);
  38.  
  39.         /* print out the values */
  40.         
  41.         x = *(long *)vread(handle, 10L);
  42.         printf ("x[10] = %d\n",x);
  43.         
  44.         x = *(long *)vread(handle, 99999L);
  45.         printf ("x[99999] = %d\n",x);
  46.         
  47.         vfree(handle);
  48.         
  49.         vclose();
  50. }
  51.