DosSubAllocMem

From EDM2
Jump to: navigation, search

DosSubAllocMem allocates a memory block from a memory pool created using DosSubSetMem.

Syntax

DosSubAllocMem( pOffset, pBlockOffset, ulSize )

Parameters

PVOID pOffset (input)
This is the offset of the memory pool from which the memory block is to be allocated.
PPVOID pBlockOffset (output)
This is a pointer to a longword, in which the offset of the allocated memory block is to be stored.
ULONG ulSize (input)
The size, in bytes, of the memory block requested.

Returns

APIRET rc

The following values can be returned

0 NO_ERROR
87 ERROR_INVALID_PARAMETER
311 ERROR_DOSSUB_NOMEM
532 ERROR_DOSSUB_CORRUPTED


Usage Explanation

The size should be a multiple of 8 bytes. If it is not, the system will round it up. The maximum value is the size of the memory pool initialized with DosSubSetMem minus 64 bytes.

Gotchas

The maximum value is the size of the memory pool initialized with DosSubSetMem minus 64 bytes.

Sample Code

#define INCL_DOSMEMMGR
#include <os2.h>
#include <bsememf.h>

PVOID Offset;
		/* Offset to the memory pool from which the */
		/* memory is to be allocated.               */

PPVOID BlockOffset;
		/* Pointer to a variable that will receive the */
		/* offset of the suballocated memory.          */

ULONG Size;
		/* The requested size in bytes. */

APIRET rc;
		/* Just to take care of the return code */

/* Use DosSubSetMem to create a memory pool and set the Offset */
/* variable to the address of this memory pool.                */

Size = 57;
		/* Rounded up to 64 bytes. */

rc = DosSubAllocMem( Offset, BlockOffset, Size);
		/* The BlockOffset variable will now contain the address */
		/* of the memory block we have allocated from the        */
		/* memory pool.                                          */

if (rc != 0)
{
   /* We have an error we must take care of. */
}

See Also