DosFreeSeg: Difference between revisions
mNo edit summary |
mNo edit summary |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
==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:Return code descriptions are: | |||
Return code descriptions are: | *0 NO_ERROR | ||
* 0 | *5 ERROR_ACCESS_DENIED | ||
* 5 | *212 ERROR_LOCKED | ||
* 212 | |||
==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. | 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 DosFreeSeg. The recipient, in turn, frees the selector passed to it, after it has accessed the shared memory with DosGetSeg. | 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. | 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: | ||
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. | ||
== | ==Bindings== | ||
===C | ===C === | ||
<PRE> | <PRE> | ||
#define INCL_DOSMEMMGR | #define INCL_DOSMEMMGR | ||
Line 33: | Line 32: | ||
USHORT rc = DosFreeSeg(Selector); | USHORT rc = DosFreeSeg(Selector); | ||
SEL | SEL Selector; /* Selector */ | ||
USHORT rc; /* return code */ | |||
</PRE> | |||
===MASM === | |||
<PRE> | |||
EXTRN DosFreeSeg:FAR | |||
INCL_DOSMEMMGR EQU 1 | |||
PUSH WORD Selector ;Selector | |||
CALL DosFreeSeg | |||
Returns WORD | |||
</PRE> | </PRE> | ||
This example allocates a segment of 30,250 bytes and then discards the segment. | |||
==Example Code== | |||
This example allocates a segment of 30,250 bytes and then discards the segment. | |||
<PRE> | <PRE> | ||
#define INCL_DOSMEMMGR | #define INCL_DOSMEMMGR | ||
Line 52: | Line 63: | ||
rc = DosFreeSeg(Selector); /* Segment selector */ | rc = DosFreeSeg(Selector); /* Segment selector */ | ||
</PRE> | </PRE> | ||
[[Category: | [[Category:Dos16]] |
Latest revision as of 03:50, 26 January 2020
This call deallocates a memory segment.
Syntax
DosFreeSeg (Selector)
Parameters
- Selector (SEL) - input
- Selector of the segment to be freed.
Return Code
- rc (USHORT) - return
- Return code descriptions are:
- 0 NO_ERROR
- 5 ERROR_ACCESS_DENIED
- 212 ERROR_LOCKED
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 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
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:
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.
Bindings
C
#define INCL_DOSMEMMGR USHORT rc = DosFreeSeg(Selector); SEL Selector; /* Selector */ USHORT rc; /* return code */
MASM
EXTRN DosFreeSeg:FAR INCL_DOSMEMMGR EQU 1 PUSH WORD Selector ;Selector CALL DosFreeSeg Returns WORD
Example Code
This example allocates a segment of 30,250 bytes and then discards the segment.
#define INCL_DOSMEMMGR #define NUMBER_OF_BYTES 30250 #define ALLOC_FLAG SEG_GETTABLE SEL Selector; USHORT rc; rc = DosAllocSeg(NUMBER_OF_BYTES, /* # of bytes requested */ &Selector, /* Selector allocated */ ALLOC_FLAG); /* Allocation flags */ rc = DosFreeSeg(Selector); /* Segment selector */