📄 stratst.c
字号:
/*
STRATST.C - Jim Kyle - June 5, 1990
demonstrates RAM-management strategy function
*/
#include <dos.h>
#include <stdio.h>
union REGS reg;
struct SREGS seg;
unsigned bigblok, tinyblok;
char *codes[] = { "First-fit", " Best-fit", " Last-fit" };
unsigned int GetRam ( unsigned para ) /* paragraphs! */
{ reg.x.bx = para;
reg.x.ax = 0x4800; /* get RAM from DOS */
intdos( ®, ® );
printf("Got blk at %04X, size=%u\n", reg.x.ax, reg.x.bx );
return reg.x.ax;
}
void RelRam ( unsigned segmt ) /* release RAM to DOS */
{ segread( &seg );
seg.es = segmt;
reg.x.ax = 0x4900;
printf("Released block at %04X\n", seg.es );
intdosx( ®, ®, &seg );
}
void SetStrat ( char strat )
{ reg.x.ax = 0x5801; /* set strategy code */
reg.h.bl = strat;
intdos( ®, ® );
}
void GetStrat ( void )
{ reg.x.ax = 0x5800; /* read strategy code */
intdos( ®, ® );
printf("Strategy code: %u (%s): ",
reg.x.ax, codes[reg.x.ax] );
}
void main ( void )
{ bigblok = GetRam ( 0x100 ); /* allocate big block */
GetRam ( 0x080 ); /* allocate a fence */
tinyblok = GetRam ( 0x080 ); /* allocate tiny block */
GetRam ( 0x080 ); /* allocate a fence */
RelRam ( bigblok ); /* now free two blocks */
RelRam ( tinyblok ); /* but leave fences */
SetStrat ( 0 ); /* set first-fit */
GetStrat ();
RelRam ( GetRam ( 0x80 )); /* get, then release */
SetStrat ( 1 ); /* set best-fit */
GetStrat ();
RelRam ( GetRam ( 0x80 )); /* get, then release */
SetStrat ( 2 ); /* set last-fit */
GetStrat ();
RelRam ( GetRam ( 0x80 )); /* get, then release */
SetStrat ( 0 ); /* set first-fit at end */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -