Function _momAlloc() Foundation

Creates a new memory object and returns its handle.

Syntax
MomHandle _momAlloc(ULONG size);
Parameters
ULONG size
Size needed for the memory object in bytes (the size is NOT limited).
Return

This function returns the handle of the created memory object. When not enough memory is available or another error occurs, the value MOM_NULLHANDLE is returned. MOM_NULLHANDLE is never a valid handle of a successfully created memory object.

Description

_momAlloc() is used to create a new memory object. The newly created object always has an even number of bytes, but at least <size> bytes. A new memory object is not automatically assigned a default value. This means that until it is initialized by the programmer, its value is meaningless.

A memory object can not be created when there are no more free handles or not enough memory is available for the object. The cause of a creation error can be checked with _conLastError().

As soon as the memory object is no longer needed, _momFree() must be called. This is important because garbage collection is not done for objects created with _momAlloc(). Responsibility for the management of these objects lies completely with the C programmer.

Examples
/* 
Generate a memory object and initialize with NULLs. 
*/ 
#include "xppcon.h" 

MomHandle  hNew; 
BYTE      *pNew; 
LONG       size = 50; 

hNew = _momAlloc(size); 
if (hNew != MOM_NULLHANDLE) 
{ 
pNew = _momLock(hNew); 

while (size-- > 0) 
     *pNew++ = 0; 

_momUnlock(hNew); 
} 
else 
{ 
/* ... error handling */ 
} 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.