home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume5 / malloc.uport / t.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-03  |  635 b   |  34 lines

  1. #include <stdio.h>
  2. #include <malloc.h>
  3.  
  4. main(argc, argv)
  5. int argc;
  6. char *argv[];
  7. {
  8.     char *p;
  9.     int size,i,j;
  10.     if (argc!=2)
  11.     {
  12.         printf("%s: Usage - t number \n",argv[0]);
  13.         printf(" Where 'number' is the number of kilobytes to allocate\n");
  14.         exit(1);
  15.     }
  16.  
  17.     if ((size=atoi(argv[1])) == 0)
  18.     {
  19.         printf("%s: Bad argument, must be integer in kilobytes",argv[0]);
  20.         exit(1);
  21.     }
  22.     
  23.     for (i=0; i<size; i++)
  24.         for (j=0; j<10; j++)
  25.             if ((p=malloc(100))==NULL)
  26.             {
  27.                 printf("\nNot enough memory available\n");
  28.                 printf("Was only able to allocate %ld bytes",i*1024L+j*100L);
  29.                 exit(2);
  30.             } else putchar('.');
  31.     putchar('\n');
  32.     return 0;
  33. }
  34.