Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
DosAllocShrSeg (1.2)
◄Function Group► ◄Overview► ◄Changes► ◄Up► ◄Next► ◄Previous►
────────────────────────────────────────────────────────────────────────────
#define INCL_DOSMEMMGR
USHORT DosAllocShrSeg(usSize, pszSegName, psel)
USHORT usSize; /* number of bytes requested */
PSZ pszSegName; /* pointer to segment name */
PSEL psel; /* pointer to variable for selector allocated */
The DosAllocShrSeg function allocates a shared-memory segment and copies the
segment selector to the specified variable.
A shared-memory segment can be accessed by any process that can identify the
segment name. A process can retrieve a selector for the segment by
specifying the name in a call to the DosGetShrSeg function. (Shared segments
allocated by using the DosAllocSeg function must be explicitly given or
retrieved by using the DosGiveSeg and DosGetSeg functions.)
Parameter Description
────────────────────────────────────────────────────────────────────────────
usSize Specifies the number of bytes to be allocated. This number can
be any value in the range 0 through 65,535. If this value is
zero, the function allocates 65,536 bytes.
pszSegName Points to a null-terminated string that identifies the shared
memory segment. The string must have the following form:
\sharemem\name
The segment name (name) must have the same format as an MS OS/2
filename and must be unique. For example, the name
\sharemem\public.dat is acceptable.
psel Points to the variable that receives the segment selector.
Return Value
The return value is zero if the function is successful. Otherwise, it is an
error value, which may be one of the following:
ERROR_ALREADY_EXISTS
ERROR_INVALID_NAME
ERROR_NOT_ENOUGH_MEMORY
Comments
The DosFreeSeg function frees the segment. The segment will not be discarded
from memory until the last process using it calls DosFreeSeg.
DosAllocShrSeg can be issued from ring 2, but the shared-memory segment will
be allocated as a ring-3 segment.
Example
This example calls the DosAllocShrSeg function to allocate 26,953 bytes. It
gives the memory the name "\sharemem\abc.mem" so that other processes can
use the memory if they know the name.
SEL sel;
DosAllocShrSeg(26953, /* bytes to allocate */
"\\sharemem\\abc.mem", /* memory name */
&sel); /* selector address */
See Also
DosAllocHuge, DosAllocSeg, DosFreeSeg, DosGetSeg, DosGetShrSeg, DosGiveSeg
♦