home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / d / djdev108.zip / SAMPLES / PAGETEST / PAGETEST.C
C/C++ Source or Header  |  1991-07-20  |  824b  |  44 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <pc.h>
  4.  
  5. main(int argc, char **argv)
  6. {
  7.   unsigned long pmax, p, cs, i;
  8.   unsigned long *pp, *pbase;
  9.  
  10.   if (argc < 2)
  11.     return;
  12.  
  13.   pmax = atoi(argv[1]) / 4;
  14.   printf("%d pages\n", pmax);
  15.  
  16.   pbase = (unsigned long *)sbrk(pmax*4096);
  17.   for (p=0; p<pmax; p++)
  18.   {
  19.     printf("\rinit page %d  ", p);
  20.     fflush(stdout);
  21.     pp = pbase + p*1024;
  22.     cs = 0;
  23.     for (i=0; i<1023; i++)
  24.     {
  25.       pp[i] = random();
  26.       cs += pp[i];
  27.     }
  28.     pp[i] = cs;
  29.   }
  30.   printf("\r                         \r");
  31.   while (!kbhit())
  32.   {
  33.     p = random() % pmax;
  34.     printf("\rpage %d  ", p);
  35.     fflush(stdout);
  36.     pp = pbase + p*1024;
  37.     cs = 0;
  38.     for (i=0; i<1023; i++)
  39.       cs += pp[i];
  40.     if (pp[i] != cs)
  41.       printf("Bad cs!\n");
  42.   }
  43. }
  44.