|
Reference · Data types Standard C · assert.h · complex.h · ctype.h · fenv.h · float.h · locale.h · math.h · setjmp.h · signal.h · stdarg.h · stddef.h · stdio.h · stdlib.h · string.h · time.h Standard C++ · IOstream · new Win32 · gc.h DOS, DOS32, Win16 · bios.h · cerror.h · disp.h · dos.h · dos.h part 2 · emm.h · handle.h · int.h · msmouse.h · sound.h · swap.h · tsr.h · winio.h Other C · bitops.h · conio.h · controlc.h · direct.h · fltpnt.h · io.h · page.h · process.h · search.h · sys\stat.h · tabsize.h · trace.h · utime.h · unmangle.h · util.h Other C++ · regexp.h · class complex |
Expanded Memory ManagementThis chapter describes:
The current implementation uses the facilities of Expanded Memory
Specification (EMS) 3.2 to ensure the widest possible compatibility.
Applications written using the EMM functions or the __handle
pointer system are therefore compatible with expanded memory
managers for both EMS 3.2 and the newer EMS 4.0, as well as with
the EMS facilities provided by MS-DOS versions 4.x and 5.0.
#include <stdio.h>
#include <stdlib.h>
#include <EMM.h>
#define HANDLES 4
/* chkout: make sure an EMM supervisor is
installed. */
void chkout(void)
{
int i, version;
float ver_no;
if (EMM_init()) {
printf("Unable to initiate EMS driver\n");
exit(EXIT_FAILURE);
}
version = EMM_getversion();
ver_no = version/ 16+ version% 16/ 10.0;
printf("EMS driver detected,
version %1.1f\n", ver_no);
printf("\tlogical page\t\tsegment\n");
for (i = 0; i < 4; i++) {
printf("\t% d\t\t\t% lp\n", i, EMM_physpage(i));
}
printf("\n");
}
/* check that allocation worked */
void check_aloc(void)
{
int i, noh;
struct EMM_handle_s *hp;
noh = EMM_gethandlecount();
if ((hp = calloc(noh, sizeof(struct
EMM_handle_s))) == NULL) {
printf("Insufficient Memory: function
check_aloc\n");
exit(EXIT_FAILURE);
}
EMM_gethandlespages(hp);
printf("\thandle no.\t\tpages\n");
for (i = 0; i < noh; i++) {
printf("\t% d\t\t\t% d\n", hp[i]. handle,
hp[i]. pages);
}
printf("\n");
}
use_EMM(unsigned h, int logical)
{
char message[128], *s;
char __far *src, far *dst;
src = EMM_physpage(0);
dst = EMM_physpage(1);
printf("Writing string to physical page 0 at "
"% lp\n", src);
sprintf(message,"Hello, from physical page 1
at "
"% lp", dst);
EMM_maphandle(h, logical, 0);
s = message;
while (* s)
*src++ = *s++;
printf("Reading String from EMM buffer:\n");
EMM_maphandle(h, logical, 1);
s = message;
while (* s)
*s++ = *dst++;
printf("Handle %d message= '% s'.\n", h, message);
}
int main()
{
unsigned i, usedp, thandle[HANDLES];
chkout() ;
printf("No. of active handles is %d \n",
EMM_gethandlecount());
for (i= 0; i< HANDLES; i++) {
/* Take half of what is available */
usedp = (EMM_getunalloc()+ 1)>> 1;
thandle[i] = EMM_allocpages(usedp);
printf("% d pages allocated to handle
%d\n", usedp, thandle[i]);
}
printf("No. of active handles is %d \n",
EMM_gethandlecount());
printf("Total size is %d pages\n",
EMM_gettotal());
printf("Free size is %d pages\n",
EMM_getunalloc());
check_aloc();
use_EMM(thandle[0], 0);
for (i= 0; i< HANDLES; i++) {
EMM_deallocpages(thandle[i]);
printf("[% d] H=% d freed\n", i, thandle[i]);
}
printf("Total size is %d pages\n",
EMM_gettotal());
printf("Free size is %d pages\n",
EMM_getunalloc());
printf("Done with EMM test.\n");
EMM_term();
return EXIT_SUCCESS;
}
emm_allocpagesHeaderemm.h Prototype int emm_allocpages(unsigned no_pages) Description The emm_allocpages function uses the Expanded Memory Manager (EMM) to allocate the required number of expanded memory (logical) 16KB pages. The number of pages to be allocated should not exceed the number of free pages remaining, otherwise an error will occur. Use emm_getunalloc to check the number of free pages available. When you use emm_allocpages to allocate expanded memory, you must use EMM functions to manage this memory. Return Value A unique handle allocated by the Expanded Memory Manager. If there are no handles available, a fatal error is returned. See Also emm_deallocpages emm_getunalloc emm_deallocpagesHeaderemm.h Prototype void emm_deallocpages(int handle) Description The emm_deallocpages function frees the expanded memory pages associated with the specified Expanded Memory Manager (EMM) handle. Return Value None Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_allocpages emm_gethandlecountHeaderemm.h Prototype int emm_gethandlecount (void); Description The emm_gethandlecount function uses the Expanded Memory Manager (EMM) to return the number of EMM handles currently active. The operating system is allocated handle 0, and this handle is always active. Thus the minimum number of active handles is 1. Return Value The number of active handles (minimum 1). Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_allocpages emm_gethandlespagesHeaderemm.h Prototype int emm_gethandlespages(struct emm_handle_s *p); Description The emm_gethandlespages returns the number of pages currently allocated to each of the active Expanded Memory Manager (EMM) handles. It is passed a pointer to an array of structures of type emm_handle_s (defined in emm. h). Return Value Returns zero if successful. Otherwise, a non-zero value is returned. Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_allocpages emm_getpagemapHeaderemm.h Prototype void emm_getpagemap(void *pmptr); Description The emm_getpagemap function uses the Expanded Memory Manager (EMM) to store the current page mapping context into the buffer pointed to by pmptr. No EMM handle is required (unlike emm_savepagemap). To determine the buffer size needed to store the page mapping context, use emm_getpagemapsize. Return Value None Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_getpagemapsize emm_savepagemap emm_getpagemapsizeHeaderemm.h Prototype unsigned emm_getpagemapsize(void); Description The emm_getpagemapsize function uses the Expanded Memory Manager (EMM) to obtain the size of the buffer needed to store the current page mapping context. Use this function to obtain the buffer size needed by emm_getpagemap, emm_setpagemap, and emm_getsetpagemap. Return Value The size of the buffer required. Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_getpagemap emm_getsetpagemap emm_setpagemap emm_getsetpagemapHeaderemm.h Prototype void emm_getsetpagemap(void *dst, void *src); Description The emm_getsetpagemap function uses the Expanded Memory Manager (EMM) to store the current page mapping context in the buffer dst, and then set the mapping context using the new values provided in the buffer src. This is the equivalent of doing emm_getpagemap(dst) followed by emm_setpagemap(src). No EMM handle is required (unlike emm_savepagemap). Use emm_getpagemapsize to determine the size of the dst buffer needed to store the current page mapping information. Return Value None Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_getpagemap emm_getpagemapsize emm_setpagemap emm_gettotalHeaderemm.h Prototype unsigned emm_gettotal(void); Description The emm_gettotal function uses Expanded Memory Manager (EMM) to get the total number of existing 16KB pages of expanded memory. Some of these pages may already be allocated. Use emm_getunalloc to get the number of free (unallocated) pages. Return Value Returns the total number of 16KB logical pages which are present. Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_getunalloc emm_getunallocHeaderemm.h Prototype unsigned emm_getunalloc(void); Description The emm_getunalloc function uses the Expanded Memory Manager (EMM) to obtain the number of 16KB logical pages of expanded memory that are currently free and available for allocation. Use this function to find out how many pages are available before you call emm_allocpages. Return Value Returns the number of 16KB pages available for allocation. Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_allocpages emm_getversionHeaderemm.h Prototype int emm_getversion(void); Description The emm_getversion function obtains the version number of the Expanded Memory Manager (EMM) software. Return Value Returns the version number of the Expanded Memory Manager as two hexadecimal digits in the form 0x32 where 3 is the major version and 2 the minor. Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_initHeaderemm.h Prototype int emm_init(void); Description The emm_init function tests for the presence of the Expanded Memory Manager (EMM) driver as recommended in the Expanded Memory Specification. The technique of tracing through the interrupt vector to find the name of the device driver is adopted since it can be safely used by interrupt handlers and memory resident software. Return Value Returns zero if an EMM is installed. Returns a non-zero value if an EMM is not installed or is not operating correctly. Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_maphandleHeaderemm.h Prototype void emm_maphandle(int handle, unsigned logical, unsigned physical); Description The emm_maphandle function uses the Expanded Memory Manager (EMM) to map the logical page logical (which belongs to handle) onto the specified physical page in the EMM page frame. Return Value None Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_physpageHeaderemm.h Prototype void __far* emm_physpage(int page); Description The emm_physpage function gets the address of the start of the specified Expanded Memory Manager (EMM) page. This page must be in the range 0 to 3. Return Value Returns a far pointer to the base address of page, or a NULL pointer if an error occurred. Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_restorepagemapHeaderemm.h Prototype void emm_restorepagemap(int handle); Description The emm_restorepagemap function uses the Expanded Memory Manager (EMM) to restore a mapping context for a specified handle that has been saved previously with emm_savepagemap. Only one mapping context can be saved and restored for each handle. Return Value None Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_savepagemap emm_savepagemapHeaderemm.h Prototype void emm_savepagemap(int handle); Description The emm_savepagemap function uses the Expanded Memory Manager (EMM) to save the current logical/ physical page mapping context for the specified handle. The context is restored using emm_restorepagemap. Only one such context can be saved for each handle. There are a limited number of such contexts that can be saved, and therefore any application should strive to require no more than 1. This function generates a fatal error if there is no space to save the mapping context. Return Value None Compatibility DOS Windows 3.x Phar Lap DOSX Win32 emm_setpagemapHeaderemm.h Prototype void emm_setpagemap(void *pmptr); Description The emm_setpagemap function uses the Expanded Memory Manager (EMM) to load a new page mapping context from the pmptr buffer. No EMM handle is required (unlike emm_restorepagemap). Return Value None Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_restorepagemap emm_termHeaderemm.h Prototype void emm_term(void); Description The emm_term function terminates the use of the Expanded Memory Manager (EMM). Return Value None Compatibility DOS Windows 3.x Phar Lap DOSX Win32 See Also emm_init |