home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / pmod01 / source / memtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-10  |  1.6 KB  |  64 lines

  1. /****************************************************************************
  2. *
  3. *                          Protected Mode Library
  4. *
  5. *                   Copyright (C) 1994 SciTech Software.
  6. *                            All rights reserved.
  7. *
  8. * Filename:        $RCSfile: memtest.c $
  9. * Version:        $Revision: 1.1 $
  10. *
  11. * Language:        ANSI C
  12. * Environment:    any
  13. *
  14. * Description:    Test program to determine just how much memory can be
  15. *                allocated with the compiler in use. Compile and link
  16. *                with the appropriate command line for your DOS extender.
  17. *
  18. *                Functions tested:    malloc()
  19. *
  20. * $Id: memtest.c 1.1 1994/03/10 09:05:43 kjb release $
  21. *
  22. ****************************************************************************/
  23.  
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <conio.h>
  28. #include "pmode.h"
  29.  
  30. void main(void)
  31. {
  32.     char *p;
  33.     unsigned long allocs;
  34.  
  35.     printf("Program running in ");
  36.     switch (_PMODE_modeType) {
  37.         case PMODE_realMode:
  38.             printf("real mode.\n\n");
  39.             break;
  40.         case PMODE_286:
  41.             printf("16 bit protected mode.\n\n");
  42.             break;
  43.         case PMODE_386:
  44.             printf("32 bit protected mode.\n\n");
  45.             break;
  46.         }
  47.  
  48.     for (allocs = 0; ; allocs++) {
  49.         if ((p = malloc(1024)) != 0) {            /* in 1k blocks */
  50.             memset(p, 0, 1024); /* touch every byte             */
  51.             *p = 'x';           /* do something, anything with    */
  52.             p[1023] = 'y';      /* the allocated memory          */
  53.  
  54.             printf("Allocated %lu bytes\r", allocs << 10);
  55.             }
  56.         else
  57.             break;
  58.         if (kbhit() && (getch() == 0x1B))
  59.             break;
  60.         }
  61.  
  62.     printf("\n\nAllocated total of %lu bytes\n", allocs << 10);
  63. }
  64.