en:docs:fapi:dosfreeseg

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:docs:fapi:dosfreeseg [2021/08/20 03:44] prokusheven:docs:fapi:dosfreeseg [2021/12/05 09:56] (current) prokushev
Line 4: Line 4:
 This call deallocates a memory segment. This call deallocates a memory segment.
  
-==Syntax==+===== Syntax =====
  
-  DosFreeSeg (Selector)+<code c> 
 +DosFreeSeg (Selector) 
 +</code>
  
-==Parameters==+===== Parameters =====
  
   * Selector ([[SEL]]) - input : Selector of the segment to be freed.   * Selector ([[SEL]]) - input : Selector of the segment to be freed.
  
-==Return Code==+===== Return Code =====
  
-  rc (USHORT) - return+rc ([[USHORT]]) - return
  
 Return code descriptions are: Return code descriptions are:
Line 21: Line 23:
   * 212       ERROR_LOCKED   * 212       ERROR_LOCKED
  
-==Remarks==+===== Remarks =====
  
-DosFreeSeg frees selectors to segments returned by allocation calls to [[DosAllocSeg]], [[DosAllocShrSeg]], and [[DosAllocHuge]]. In addition, DosFreeSeg frees a selector returned by a call to [[DosCreateCSAlias]]. If a CS alias selector has been created for a data segment by a call to DosCreateCSAlias, the CS alias selector is still valid after the segment's data selector has been freed. 
  
-When allocated memory is shared, all selectors to the shared memory must be freed before the memory is deallocated. For example, if memory allocated by DosAllocSeg or DosAllocHuge has been given to another process with [[DosGiveSeg]], the giver usually frees its selector by a call to DosFreeSegThe recipient, in turn, frees the selector passed to it, after it has accessed the shared memory with [[DosGetSeg]].+DosFreeSeg frees selectors to segments returned by allocation calls to [[DosAllocSeg]], [[DosAllocShrSeg]], and [[DosAllocHuge]]. In addition, DosFreeSeg frees selector returned by a call to [[DosCreateCSAlias]]If a CS alias selector has been created for a data segment by a call to [[DosCreateCSAlias]], the CS alias selector is still valid after the segment's data selector has been freed.
  
-DosFreeSeg decrements the reference count for named shared segments allocated by DosAllocShrSeg. Access to the segment with [[DosGetShrSeg]] increments this count. When the count is 0, the memory is deallocated. +When allocated memory is shared, all selectors to the shared memory must be freed before the memory is deallocated. For example, if memory allocated by [[DosAllocSeg]] or [[DosAllocHuge]] has been given to another process with [[DosGiveSeg]], the giver usually frees its selector by a call to DosFreeSeg. The recipient, in turn, frees the selector passed to it, after it has accessed the shared memory with [[DosGetSeg]]. 
 + 
 +DosFreeSeg decrements the reference count for named shared segments allocated by [[DosAllocShrSeg]]. Access to the segment with [[DosGetShrSeg]] increments this count. When the count is 0, the memory is deallocated.  
 + 
 +==== Family API Considerations ====
  
-===Family API Considerations=== 
  
 Some options operate differently in the DOS mode than in OS/2 mode. Therefore, the following restriction applies to DosFreeSeg when coding for the DOS mode: Some options operate differently in the DOS mode than in OS/2 mode. Therefore, the following restriction applies to DosFreeSeg when coding for the DOS mode:
Line 35: Line 39:
 If DosFreeSeg is issued on a CSAliased segment it deallocates the associated memory. This is inconsistent with the OS/2 mode, because DosFreeSeg must be performed on both the original and CSAliased selectors.  If DosFreeSeg is issued on a CSAliased segment it deallocates the associated memory. This is inconsistent with the OS/2 mode, because DosFreeSeg must be performed on both the original and CSAliased selectors. 
  
-==Example Code== +===== Example Code =====
-===C Binding===+
  
 +==== C Binding ====
 +
 +<code c>
   #define INCL_DOSMEMMGR   #define INCL_DOSMEMMGR
      
Line 45: Line 51:
      
   USHORT           rc;            /* return code */   USHORT           rc;            /* return code */
 +</code>
 This example allocates a segment of 30,250 bytes and then discards the segment.  This example allocates a segment of 30,250 bytes and then discards the segment. 
  
 +<code c>
   #define INCL_DOSMEMMGR   #define INCL_DOSMEMMGR
      
Line 60: Line 67:
                      ALLOC_FLAG);         /* Allocation flags */                      ALLOC_FLAG);         /* Allocation flags */
    rc = DosFreeSeg(Selector);            /* Segment selector */    rc = DosFreeSeg(Selector);            /* Segment selector */
 +</code>
  
-===MASM Binding===+==== MASM Binding ====
  
 +<code asm>
   EXTRN  DosFreeSeg:FAR   EXTRN  DosFreeSeg:FAR
   INCL_DOSMEMMGR      EQU 1   INCL_DOSMEMMGR      EQU 1
Line 68: Line 77:
   PUSH   WORD    Selector      ;Selector   PUSH   WORD    Selector      ;Selector
   CALL   DosFreeSeg   CALL   DosFreeSeg
 +</code>
 Returns WORD Returns WORD
  
 +===== Note =====
  
- 
-====== Note ====== 
  
 Text based on http://www.edm2.com/index.php/DosFreeSeg Text based on http://www.edm2.com/index.php/DosFreeSeg