|
|
1.1 root 1: /* This example illustrates allocating a huge segment, addressing
2: * the segment, growing & shrinking the segment and freeing the
1.1.1.2 ! root 3: * segment. The following MS OS/2 functions are illustrated here:
! 4: * DosAllocHuge, DosReAllocHuge, DosFreeSeg
1.1 root 5: *
6: * This example allocates a huge segment. It writes a value to one of the
7: * words in the huge segment. It grows the segment and then shrinks the
8: * segment back to its original size. It then checks if the segment contains
9: * the value that was written previously. If not, it prints an error message.
10: * It then frees the huge segment. This example is intended to illustrate
11: * how to manage and access huge segments - it doesn't perform any useful
12: * function.
13: *
1.1.1.2 ! root 14: * Created by Microsoft Corp. 1986
1.1 root 15: */
16:
1.1.1.2 ! root 17: #define INCL_DOSMEMMGR
1.1 root 18:
1.1.1.2 ! root 19: #include <os2def.h> /* contains SELECTOROF and OFFSETOF macros */
! 20: #include <bsedos.h> /* contains MS OS/2 function declarations */
! 21:
! 22: /* used in DosAllocHuge call */
1.1 root 23: #define NUMSEGA 3 /* number of segments in huge segment */
24: #define SIZEA 8000 /* number of bytes in last segment */
25: #define PRIVATE 0 /* huge segment will not be shared */
26: #define MAXSEGS 6 /* max number of 64k segments in huge segment*/
27: #define WORDA 35000 /* a word in segment 2 in huge segment */
28: #define VALUEA 15 /* value to write into WORDA */
29:
1.1.1.2 ! root 30: /* used in DosReAllocHuge call (growing the segment) */
1.1 root 31: #define NUMSEGR 5 /* number of segments in huge segment */
32: #define SIZER 12000 /* number of bytes in last segment */
33:
34: main ()
35: {
1.1.1.2 ! root 36: SEL FirstSelector; /* first selector for huge segment */
1.1 root 37: int /*huge*/ *HugeSeg; /* pointer to a huge segment */
38:
39: /* allocate a huge segment */
1.1.1.2 ! root 40: DosAllocHuge (NUMSEGA, SIZEA, &FirstSelector, MAXSEGS, PRIVATE);
1.1 root 41:
42: /* compute the address to the huge segment */
1.1.1.2 ! root 43: SELECTOROF(HugeSeg) = FirstSelector;
! 44: OFFSETOF(HugeSeg) = 0;
1.1 root 45: HugeSeg[WORDA] = VALUEA;
46:
47: /* grow the huge segment */
1.1.1.2 ! root 48: DosReallocHuge (NUMSEGR, SIZER, FirstSelector);
1.1 root 49:
50: /* shrink the huge segment to its orginal size */
1.1.1.2 ! root 51: DosReallocHuge (NUMSEGA, SIZEA, FirstSelector);
1.1 root 52:
53: /* WORDA should still contain VALUEA */
54: if (HugeSeg[WORDA] != VALUEA)
55: printf ("*** error: unexpected value in huge segment ***\n");
56:
1.1.1.2 ! root 57: DosFreeSeg (FirstSelector); /* free the huge segment */
1.1 root 58: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.