home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / PGMUTL / SWITCH22.ZIP / SWDEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-22  |  5.3 KB  |  117 lines

  1. /****************************************************** Switch! Demo
  2. ******************************************************* Version 2.0
  3. ******************************************************* Tab Size:  4 ******
  4. ******************************************************* December 19, 1988
  5. ******************************************************* Curtis Little
  6. ******************************************************* 1087 Murrietta Blvd
  7. *******************************************************                #244
  8. ******************************************************* Livermore, CA 94550
  9. *
  10. *    NOTES:  This demo was designed for Turbo C.  If you don't have Turbo C
  11. *    you may need to change the calls from cputs to puts.  In addition if
  12. *    you change cputs to puts you should get rid of the \r at the end of
  13. *    each line to be printed.
  14. *
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <alloc.h>
  20.  
  21. #define BLK_SIZE    3000L            /* size of memory chunks ate */
  22. #define PRG_SIZE    13000L            /* approx size of the demo itself */
  23.  
  24. int main( void )
  25. {
  26.     int mmem;                    /* to hold the amount of memory required */
  27.     int i = 0;
  28.     char mybuff[6];                /* temp buffer */
  29.     char mprog[83];                /* to hold the program name and parameters */
  30.  
  31.     /* eat up a lot of memory if possible */
  32.     while (1) {
  33.         if (((char *)malloc( BLK_SIZE )) == NULL)    /* eat chunks till all gone */
  34.             break;
  35.         i++;                        /* no need to save the pointers */
  36.                                 /* since just eating memory here */
  37.     }
  38.  
  39.     printf( "\x01b[2J\n" );        /* clear the screen */
  40.  
  41.  
  42.     cputs( "\n\n     This demo demonstrates the usefullness of Switch!.  Switch! is an\n\r" );
  43.     cputs( "     assembly function that frees up as much memory as needed to run\n\r" );
  44.     cputs( "     another program.  Switch! saves the memory used by your C and/or\n\r" );
  45.     cputs( "     Assembly application to a temporary disk file (registered versions\n\r" );
  46.     cputs( "     of Switch! use EMS if present) then frees it up for use by DOS. It\n\r" );
  47.     cputs( "     can free up all but about 8K of available memory!!  To see how\n\r" );
  48.     cputs( "     helpful Switch! is this program allows you to specify a program \n\r" );
  49.     cputs( "     to run and the amount of memory required by the program.  Use a \n\r" );
  50.     cputs( "     map program or CHKDSK to see how much memory you have free before \n\r" );
  51.     cputs( "     running this demo.  Then specify CHKDSK as the program to run from \n\r" );
  52.     cputs( "     within this demo and specify 0 for the amount of memory required \n\r" );
  53.     cputs( "     (a value of 0 causes Switch! to free all memory possible).  You'll \n\r" );
  54.     cputs( "     be amazed how much memory becomes available!\n\n\r" );
  55.     cputs( "     Switch! was designed to work with ANY language that allows you to\n\r" );
  56.     cputs( "     call external C functions (using standard C parameter passing\n\r" );
  57.     cputs( "     conventions).  It doesn't matter how big the program is!  You can\n\r" );
  58.     cputs( "     free most of the used memory to run another program!  Using Switch!\n\r" );
  59.     cputs( "     you can run a 630K program from within a 640K program by using a\n\r" );
  60.     cputs( "     simple function call.  With Switch! there's no worries about memory!\n\n\r" );
  61.     cputs( "     The syntax for calling the C version of Switch! is:\n\n\r" );
  62.     cputs( "     switch_(Drive to use, K mem needed, Program to run and parameters)\n\r" );
  63.     getch();
  64.  
  65.  
  66.     while (1) {
  67.         /* initialize the variables */
  68.         mprog[0] = '\0';
  69.         mmem = 0;
  70.  
  71.         printf( "\n\nThis DEMO Program occupies approximately %ld bytes of memory.",
  72.             i * BLK_SIZE + PRG_SIZE);
  73.         /* get the program name and the amount of memory required */
  74.         cputs( "\n\r\nEnter the program to run (leave blank for DOS shell):\n\r>" );
  75.         fflush(stdin);
  76.         fgets( mprog, 80, stdin );
  77.         cputs( "\n\r Enter amount of RAM required by program (0 for all) \n\r" );
  78.         cputs( "                           (Negative number to quit): " );
  79.         fgets( mybuff, 4, stdin );
  80.         mmem = atoi( mybuff );
  81.  
  82.         /* exit the loop if the user wants to quit */
  83.         if (mmem < 0)
  84.             break;
  85.  
  86.         /* Execute the specified program using the default drive to save mem */
  87.         mmem = switch_(0,mmem, mprog);
  88.  
  89.         /* check for error */
  90.         if (mmem) {
  91.             printf( "\n\nSwitch!  Error #%d.  SWDEMO aborted.\n", mmem );
  92.             exit(mmem);
  93.         }
  94.  
  95.         cputs( "\n\r\n>> Press Any Key to Continue <<" );
  96.         getch();
  97.     }
  98.  
  99.     printf( "\x01b[2J\n" );        /* clear the screen */
  100.  
  101.     cputs("\n\n\n\n\n     Switch! only frees up the memory it needs to.  For instance, if you\n\r" );
  102.     cputs("     specify the program to run needs 64K Switch! will only save memory\n\r" );
  103.     cputs("     if there isn't already 64K free memory.  Setting the value to the \n\r" );
  104.     cputs("     minimum required by the application reduces the time it takes to\n\r" );
  105.     cputs("     Switch! applications.  To really get a feel for what Switch! can do \n\r" );
  106.     cputs("     for you use the SWITCH.OBJ file to link Switch! into your own \n\r" );
  107.     cputs("     applications and use it to call other programs.\n\n\r" );
  108.     cputs("     To register Switch! (and get the source!) please send $20.00 check \n\r" );
  109.     cputs("     or money order to:\n\n\r" );
  110.     cputs("                      Curtis Little\n\r" );
  111.     cputs("                      1087 Murrietta Blvd #244\n\r" );
  112.     cputs("                      Livermore, CA  94550\n\n\n\n\n\n\n\r" );
  113.  
  114.     exit(0);
  115. }
  116.  
  117.