en:docs:fapi:dosallocseg

Differences

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

Link to this comparison view

Next revision
Previous revision
en:docs:fapi:dosallocseg [2018/08/30 17:12] – created prokusheven:docs:fapi:dosallocseg [2021/09/17 09:18] (current) prokushev
Line 1: Line 1:
 +{{page>en:templates:fapiint}}
  
-==Syntax== +====== DosAllocSeg ======
- DosAllocSeg (Size, Selector, AllocFlags)+
  
-==Parameters== +===== Syntax =====
-;Size (USHORT) - input: Number of bytes requested. The value specified must be less than or equal to 65535. A value of zero indicates 65536 bytes. +
-;Selector (P[[SEL]]) - output: Address where the selector of the segment allocated is returned. +
-;AllocFlags (USHORT) - input: Bit indicators describing the characteristics of the segment being allocated. The bits that can be set and their meanings are: +
-:15-4 - Reserved and must be set to zero. +
-:3 - If segment is shared, it can be decreased in size by [[DosReallocSeg]]. +
-:2 - Segment may be discarded by the system in low memory situations. +
-:1 - Segment is shareable through [[DosGetSeg]]. +
-:0 - Segment is shareable through [[DosGiveSeg]].+
  
-==Return Code== +<code c> 
-;rc (USHORT) - return:Return code descriptions are: +DosAllocSeg (Size, Selector, AllocFlags) 
-*0  NO_ERROR +</code> 
-*8  ERROR_NOT_ENOUGH_MEMORY + 
-*87 ERROR_INVALID_PARAMETER+===== Parameters ===== 
 + 
 +  * Size ([[USHORT]]) - input: Number of bytes requested. The value specified must be less than or equal to 65535. A value of zero indicates 65536 bytes. 
 +  * Selector ([[PSEL]]) - output: Address where the selector of the segment allocated is returned. 
 +  * AllocFlags ([[USHORT]]) - input: Bit indicators describing the characteristics of the segment being allocated. The bits that can be set and their meanings are: 
 + 
 +^ Bit ^ Description ^ 
 +|15-4 | Reserved and must be set to zero | 
 +| 3 | If segment is shared, it can be decreased in size by [[DosReallocSeg]] | 
 +| 2 | Segment may be discarded by the system in low memory situations | 
 +| 1 | Segment is shareable through [[DosGetSeg]] | 
 +| 0 | Segment is shareable through [[DosGiveSeg]] | 
 + 
 +===== Return Code ===== 
 + 
 +rc ([[USHORT]]) - return: Return code 
 + 
 +  *0  NO_ERROR 
 +  *8  ERROR_NOT_ENOUGH_MEMORY 
 +  *87 ERROR_INVALID_PARAMETER 
 + 
 +===== Remarks =====
  
-==Remarks== 
 DosAllocSeg allows a process to allocate a data segment up to 64KB in size, which is movable and swappable by the system. If your application needs to accommodate a large data structure that exceeds the 64KB limit, [[DosAllocHuge]] may be issued to allocate multiple segments as one huge block of memory. DosAllocSeg allows a process to allocate a data segment up to 64KB in size, which is movable and swappable by the system. If your application needs to accommodate a large data structure that exceeds the 64KB limit, [[DosAllocHuge]] may be issued to allocate multiple segments as one huge block of memory.
  
 A segment allocated by DosAllocSeg with AllocFlags bit 2 set can be discarded by the system to remedy a low memory situation when the segment is not in use. Upon allocation, a discardable segment is locked and ready for access. The caller issues [[DosUnlockSeg]] when it is finished using the segment. The next time the caller needs to access the segment, it must issue [[DosLockSeg]]. During the time a segment is locked, it cannot be discarded, but it can still be swapped. A segment allocated by DosAllocSeg with AllocFlags bit 2 set can be discarded by the system to remedy a low memory situation when the segment is not in use. Upon allocation, a discardable segment is locked and ready for access. The caller issues [[DosUnlockSeg]] when it is finished using the segment. The next time the caller needs to access the segment, it must issue [[DosLockSeg]]. During the time a segment is locked, it cannot be discarded, but it can still be swapped.
  
-Allocate memory as discardable when it is needed to hold data for only short periods of time; for example, saved bit map images for obscured windows. Once the system discards a segment, the caller must reallocate the segment with DosReallocSeg and regenerate the data. Reallocating the segment automatically locks it for the first access.+Allocate memory as discardable when it is needed to hold data for only short periods of time; for example, saved bit map images for obscured windows. Once the system discards a segment, the caller must reallocate the segment with [[DosReallocSeg]] and regenerate the data. Reallocating the segment automatically locks it for the first access.
  
-A segment may also be designated as shared with another process. If a process issues DosAllocSeg with AllocFlags bit 0 set, then the segment allocated is shareable through DosGiveSeg. To share the segment in this manner, the owning process can then issue DosGiveSeg to obtain a selector for the sharer to use. The owning process then passes the selector to the sharer using some means of interprocess communication. The sharing process can use the selector to access the shared segment. If the shared segment has been designated discardable (AllocFlags bit 2 is also set), the sharer must issue DosLockSeg to lock the segment.+A segment may also be designated as shared with another process. If a process issues DosAllocSeg with AllocFlags bit 0 set, then the segment allocated is shareable through [[DosGiveSeg]]. To share the segment in this manner, the owning process can then issue [[DosGiveSeg]] to obtain a selector for the sharer to use. The owning process then passes the selector to the sharer using some means of interprocess communication. The sharing process can use the selector to access the shared segment. If the shared segment has been designated discardable (AllocFlags bit 2 is also set), the sharer must issue [[DosLockSeg]] to lock the segment.
  
 Memory allocated with DosAllocSeg is freed by a call to [[DosFreeSeg]]. Memory allocated with DosAllocSeg is freed by a call to [[DosFreeSeg]].
Line 32: Line 44:
 '''Note:''' This request may be issued from privilege level 2. However, the segment is allocated as a privilege level 3 segment. '''Note:''' This request may be issued from privilege level 2. However, the segment is allocated as a privilege level 3 segment.
  
-===Family API Considerations===+==== Family API Considerations ===
 Some options operate differently in the DOS mode than in the OS/2 mode. Therefore, the following restrictions apply to DosAllocSeg when coding for the DOS mode: Some options operate differently in the DOS mode than in the OS/2 mode. Therefore, the following restrictions apply to DosAllocSeg when coding for the DOS mode:
-* Requested Size value is rounded up to the next paragraph (16-byte).  +  * Requested Size value is rounded up to the next paragraph (16-byte).  
-* Selector is the actual segment address allocated. +  * Selector is the actual segment address allocated. 
-* AllocFlags must be set to zero.+  * AllocFlags must be set to zero.
  
-==Bindings== +===== Bindings ===== 
-===C=== + 
-<PRE>+==== C ===
 + 
 +<code c>
 #define INCL_DOSMEMMGR #define INCL_DOSMEMMGR
  
Line 50: Line 65:
  
 USHORT  rc;          /* return code */ USHORT  rc;          /* return code */
-</PRE>+</code>
  
-===MASM=== +==== MASM ===
-<PRE>+ 
 +<code asm>
 EXTRN  DosAllocSeg:FAR EXTRN  DosAllocSeg:FAR
 INCL_DOSMEMMGR      EQU 1 INCL_DOSMEMMGR      EQU 1
Line 63: Line 79:
  
 Returns WORD Returns WORD
-</PRE>+</code> 
 + 
 +==== Example Code ====
  
-==Example Code== 
 This example requests a segment of memory with 30,128 bytes. The segment can be shared with a DosGetSeg API call. This example requests a segment of memory with 30,128 bytes. The segment can be shared with a DosGetSeg API call.
-<PRE>+<code c>
 #define INCL_DOSMEMMGR #define INCL_DOSMEMMGR
  
Line 79: Line 96:
                     &Selector,           /* Selector allocated */                     &Selector,           /* Selector allocated */
                     ALLOC_FLAG);         /* Allocation flags */                     ALLOC_FLAG);         /* Allocation flags */
-</PRE>+</code>
 The following example requests a segment of memory with 4,000 bytes. The following example also shows how to suspend and resume execution of a thread within a process. The main thread creates Thread2 and allows it to begin executing. Thread2 iterates through a loop that prints a line and then sleeps, relinquishing its time slice to the main thread. After one iteration by Thread2, the main thread suspends Thread2 and then resumes it. Subsequently, Thread2 completes the remaining three iterations. The following example requests a segment of memory with 4,000 bytes. The following example also shows how to suspend and resume execution of a thread within a process. The main thread creates Thread2 and allows it to begin executing. Thread2 iterates through a loop that prints a line and then sleeps, relinquishing its time slice to the main thread. After one iteration by Thread2, the main thread suspends Thread2 and then resumes it. Subsequently, Thread2 completes the remaining three iterations.
-<PRE>+<code c>
 #define INCL_DOSPROCESS #define INCL_DOSPROCESS
  
Line 145: Line 162:
   DosSleep(SLEEPLONG);                         /* Sleep interval */   DosSleep(SLEEPLONG);                         /* Sleep interval */
 } }
-</PRE>+</code>
  
  
  
-====== Note ======+===== Note =====
  
 Text based on [[http://www.edm2.com/index.php/DosAllocSeg]] Text based on [[http://www.edm2.com/index.php/DosAllocSeg]]