File:  [OS/2 SDKs] / os2sdk / demos / examples / huge / huge.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:08 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1988, HEAD
Microsoft OS/2 SDK 03-01-1988

/* This example illustrates allocating a huge segment, addressing
 * the segment, growing & shrinking the segment and freeing the
 * segment. The following MS OS/2 functions are illustrated here:
 *	DosAllocHuge, DosReAllocHuge, DosFreeSeg
 *
 * This example allocates a huge segment. It writes a value to one of the
 * words in the huge segment. It grows the segment and then shrinks the
 * segment back to its original size. It then checks if the segment contains 
 * the value that was written previously. If not, it prints an error message. 
 * It then frees the huge segment. This example is intended to illustrate
 * how to manage and access huge segments - it doesn't perform any useful
 * function.
 *
 * Created by Microsoft Corp. 1986
 */	

#define  INCL_DOSMEMMGR

#include	<os2def.h>	/* contains SELECTOROF and OFFSETOF macros   */
#include	<bsedos.h>	/* contains MS OS/2 function declarations    */

/* used in DosAllocHuge call  */
#define NUMSEGA 3		/* number of segments in huge segment        */
#define SIZEA	8000		/* number of bytes in last segment           */
#define PRIVATE 0		/* huge segment will not be shared           */
#define MAXSEGS 6		/* max number of 64k segments in huge segment*/
#define	WORDA   35000		/* a word in segment 2 in huge segment        */
#define VALUEA  15		/* value to write into WORDA                 */

/* used in DosReAllocHuge call (growing the segment) */
#define	NUMSEGR 5		/* number of segments in huge segment        */
#define SIZER   12000		/* number of bytes in last segment           */

main ()
{
	SEL		FirstSelector;	/* first selector for huge segment */
	int /*huge*/	*HugeSeg;	/* pointer to a huge segment	   */

	/* allocate a huge segment */
	DosAllocHuge (NUMSEGA, SIZEA, &FirstSelector, MAXSEGS, PRIVATE);

	/* compute the address to the huge segment */
	SELECTOROF(HugeSeg) = FirstSelector;
	OFFSETOF(HugeSeg) = 0;
	HugeSeg[WORDA] = VALUEA;

	/* grow the huge segment */
	DosReallocHuge (NUMSEGR, SIZER, FirstSelector);

	/* shrink the huge segment to its orginal size */
	DosReallocHuge (NUMSEGA, SIZEA, FirstSelector);

	/* WORDA should still contain VALUEA */
	if (HugeSeg[WORDA] != VALUEA)
          printf ("*** error: unexpected value in huge segment ***\n");

	DosFreeSeg (FirstSelector);	/* free the huge segment */
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.