home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l440 / 2.ddi / CHAP3 / STRATST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-25  |  1.9 KB  |  66 lines

  1. /*
  2. STRATST.C - Jim Kyle - June 5, 1990
  3. demonstrates RAM-management strategy function
  4. */
  5.  
  6. #include <dos.h>
  7. #include <stdio.h>
  8.  
  9. union REGS reg;
  10. struct SREGS seg;
  11. unsigned bigblok, tinyblok;
  12. char *codes[] = { "First-fit", " Best-fit", " Last-fit" };
  13.  
  14. unsigned int GetRam ( unsigned para )   /* paragraphs!  */
  15. { reg.x.bx = para;
  16.   reg.x.ax = 0x4800;            /* get RAM from DOS     */
  17.   intdos( ®, ® );
  18.   printf("Got blk at %04X, size=%u\n", reg.x.ax, reg.x.bx );
  19.   return reg.x.ax;
  20. }
  21.  
  22. void RelRam ( unsigned segmt )  /* release RAM to DOS   */
  23. { segread( &seg );
  24.   seg.es   = segmt;
  25.   reg.x.ax = 0x4900;
  26.   printf("Released block at %04X\n", seg.es );
  27.   intdosx( ®, ®, &seg );
  28. }
  29.  
  30. void SetStrat ( char strat )
  31. { reg.x.ax = 0x5801;            /* set strategy code    */
  32.   reg.h.bl = strat;
  33.   intdos( ®, ® );
  34. }
  35.  
  36. void GetStrat ( void )
  37. { reg.x.ax = 0x5800;            /* read strategy code   */
  38.   intdos( ®, ® );
  39.   printf("Strategy code: %u (%s): ",
  40.          reg.x.ax, codes[reg.x.ax] );
  41. }
  42.  
  43. void main ( void )
  44. { bigblok = GetRam ( 0x100 );   /* allocate big block   */
  45.   GetRam ( 0x080 );             /* allocate a fence     */
  46.   tinyblok = GetRam ( 0x080 );  /* allocate tiny block  */
  47.   GetRam ( 0x080 );             /* allocate a fence     */
  48.  
  49.   RelRam ( bigblok );           /* now free two blocks  */
  50.   RelRam ( tinyblok );          /* but leave fences     */
  51.  
  52.   SetStrat ( 0 );               /* set first-fit        */
  53.   GetStrat ();
  54.   RelRam ( GetRam ( 0x80 ));    /* get, then release    */
  55.  
  56.   SetStrat ( 1 );               /* set best-fit         */
  57.   GetStrat ();
  58.   RelRam ( GetRam ( 0x80 ));    /* get, then release    */
  59.  
  60.   SetStrat ( 2 );               /* set last-fit         */
  61.   GetStrat ();
  62.   RelRam ( GetRam ( 0x80 ));    /* get, then release    */
  63.  
  64.   SetStrat ( 0 );               /* set first-fit at end */
  65. }
  66.