dos12.hlp (Table of Contents; Topic list)
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.
DosFreeSeg (1.2)
Function Group  Overview                          Up Next Previous
────────────────────────────────────────────────────────────────────────────
 
#define INCL_DOSMEMMGR
 
USHORT DosFreeSeg(sel)
SEL sel;    /* segment selector */
 
The DosFreeSeg function frees the specified memory segment. This function
accepts selectors for memory segments, shared-memory segments, huge-memory
segments, aliased code segments, and resource segments allocated by
DosGetResource. DosFreeSeg frees a shared-memory segment after the segment
is freed by the last process accessing it. DosFreeSeg frees the code-segment
selector for aliased code segments, but the corresponding data-segment
selector remains valid until it is freed.
 
The DosFreeSeg function is a family API function.
 
Parameter  Description
────────────────────────────────────────────────────────────────────────────
 
sel        Specifies the segment to free.
 
Return Value
 
The return value is zero if the function is successful. Otherwise, it is an
error value, which may be the following:
 
     ERROR_ACCESS_DENIED
 
Comments
 
DosFreeSeg can be issued from ring 2, but the segment to free must be a
ring-3 segment.
 
DosFreeSeg should not be used to free resource segments allocated by the
DosGetResource2 function. To free those segments, use the DosFreeResource
function.
 
Restrictions
 
In real mode, the following restriction applies to the DosFreeSeg function:
 
♦  A code-segment selector (created by using the DosCreateCSAlias function)
   and the corresponding data-segment selector are the same. Freeing one
   frees both.
 
Example
 
This example allocates three segments of memory, then calls the DosFreeSeg
function to free the memory:
 
SEL sel;
DosAllocHuge(3, 200, &sel, 5, SEG_NONSHARED);
    .
    .
    .
DosFreeSeg(sel);
 
See Also
 
DosAllocHuge, DosAllocSeg, DosAllocShrSeg, DosCreateCSAlias,
DosFreeResource, DosGetResource, DosGetResource2