home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l351 / 1.ddi / EXAMPLES / MEMTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-26  |  689 b   |  28 lines

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