--- os2sdk/demos/examples/alloc/alloc.c 2018/08/09 12:25:13 1.1.1.1 +++ os2sdk/demos/examples/alloc/alloc.c 2018/08/09 12:26:16 1.1.1.2 @@ -1,5 +1,5 @@ /* - * Example of DOSALLOCSEG/DOSFREESEG usage. + * Example of DosAllocSeg/DosFreeSeg usage. * * Shows how to allocate a segment, create a * pointer to it, access the segment, and free it. @@ -7,19 +7,20 @@ * specified on the command line. After all are allocated, * writes a 0 into the first byte of each. If you run this on * a system with swapping enabled you can allocate more segments - * segments than fit in physcical memory, and exercise your disk. + * than fit in physcical memory, and exercise your disk. * * This program works Family API mode, although obviously * without the benefit of virtual memory & swapping. * - * Compile as: cl -AL -G2 -Lp alloc.c + * Compile as: cl -AL -G0 -Lp alloc.c * - * Copyright (C) Microsoft Corp. 1986 + * Created by Microsoft Corp. 1986 */ +#define INCL_DOSMEMMGR -#include +#include #include -#include +#include #define SEGSIZE (16 * 1024) /* size of each segment allocated */ #define NOTSHARED 0 @@ -28,21 +29,21 @@ main(argc, argv) int argc; char *argv[]; { - unsigned *seglist; /* pointer to list of segments */ - char *p; /* pointer used to access segments */ + USHORT *seglist; /* pointer to list of segments */ + char *p; /* pointer used to access segments */ register int i, j; - int rc; /* system call return code */ + int rc; /* system call return code */ if(argc == 2) /* number of segments to allocate */ i = atoi(argv[1]); else i = 1; - seglist = (unsigned *)malloc(2 * i); /* list of segment selectors */ + seglist = (USHORT *)malloc(2 * i); /* list of segment selectors */ /* allocate segment(s) */ for(j = 0; j < i; j++) { - rc = DOSALLOCSEG(SEGSIZE, &seglist[j], NOTSHARED); + rc = DosAllocSeg(SEGSIZE, (PSEL)&seglist[j], NOTSHARED); if(rc == 0) printf("allocated segment %d\n", j); else { @@ -53,8 +54,8 @@ char *argv[]; /* write 0 into first byte of each segment */ for(j = 0; j < i; j++) { - FP_SEG(p) = seglist[j]; /* make long pointer to seg */ - FP_OFF(p) = 0; + SELECTOROF(p) = seglist[j]; /* make long pointer to seg */ + OFFSETOF(p) = 0; printf("touching segment %d\n", j); p[0] = 0; /* put zero in first byte */ } @@ -62,6 +63,6 @@ char *argv[]; /* free each segment */ for(j = 0; j < i; j++) { printf("freeing segment %d\n", j); - DOSFREESEG(seglist[j]); + DosFreeSeg(seglist[j]); } }