From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 16-JUN-1993 09:52:55.15
To:	EVERHART
CC:	
Subj:	Re: RE: shared memory under VMS: HOW?

From: JONESD@kcgl1.eng.ohio-state.edu (David Jones)
X-Newsgroups: comp.os.vms
Subject: Re: RE: shared memory under VMS: HOW?
Date: 16 Jun 1993 05:12:13 GMT
Organization: The Ohio State University
Lines: 55
Message-ID: <1vma3d$ct3@charm.magnus.acs.ohio-state.edu>
NNTP-Posting-Host: kcgl1.eng.ohio-state.edu
To: Info-VAX@KL.SRI.COM
X-Gateway-Source-Info: USENET

Jerry Leichter's code fragment makes the solution to Mr. Leitner's problem
look more complicated than it is.  If all you want is to share data between
processes, you can skip all the rigamarole with creating files by having
the $CRMPSC service create a page file section.  Here is a simpler fragment:

	#include secdef
	#include descrip
	int length;
	long inadr[2];
        struct shared *retadr[2];
	long sys$crmpsc ();
	struct dsc$descriptor gbl_secn;
        /*
         * Build the shared memory section name.
         */
        (void)strcpy(section_name, SECTION_NAME);
        gbl_secn.dsc$w_length = strlen(section_name);
        gbl_secn.dsc$b_dtype  = DSC$K_DTYPE_T;
        gbl_secn.dsc$b_class  = DSC$K_CLASS_S;
        gbl_secn.dsc$a_pointer= section_name;
	/*
	 * Create shared memory.
	 */
        inadr[0] = 0;	/* force into P0 space */
        inadr[1] = 0;
        status = sys$crmpsc( inadr, retadr,
                        0,
                        SEC$M_WRT | SEC$M_GBL | SEC$M_PAGFIL | SEC$M_EXPREG,
                        &gbl_secn,
                        0,
                        0,
                        0,
                        1,	/* number of pages */
                        0,
                        0,
                        0);
        if (status == SS$_NORMAL  || status == SS$_CREATED)
        {
           cfg_p = retadr[0];	/* init pointer to beginning of mapped mem */
           return(TRUE);
        }

The key to getting $CRMPSC to work the way you want is to understand the
subtleties of all those flag bits (SEC$M_*).  For example, if you are
emulating a unix call will that returns the address of a block of shared
memory at a new address, knowing about the SEC$M_EXPREG (expand region) flag
is crucial.


David L. Jones               |      Phone:    (614) 292-6929
Ohio State Unviversity       |      Internet:
1971 Neil Ave. Rm. 406       |               jonesd@kcgl1.eng.ohio-state.edu
Columbus, OH 43210           |               jones-d@eng.ohio-state.edu

Disclaimer: A repudiation of a claim.

