home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l352 / 1.img / EXAMPLES / MEMTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-04  |  710 b   |  31 lines

  1. /* 
  2. MEMTEST.C
  3. bcc286 memtest.c
  4. */
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. main()
  11. {
  12.     char *p;
  13.     unsigned long allocs;
  14.  
  15.     for (allocs = 0; ; allocs++)
  16.        if ((p = malloc(1024)) != 0)    /* in 1k blocks */
  17.        {
  18.            memset(p, 0, 1024); /* touch every byte */
  19.            *p = 'x';           /* do something, anything with */
  20.            p[1023] = 'y';      /* the allocated memory      */
  21.            
  22.            if (allocs && (allocs % 1024) == 0)   /* odometer */
  23.                printf("Allocated %u megabytes\r", allocs >> 10);
  24.        }
  25.        else
  26.            break;
  27.  
  28.        printf("Allocated %lu bytes\n", allocs << 10);
  29.        return 0;
  30. }
  31.