Function _momUnlock() Foundation

Ends access to a memory object.

Syntax
XPPAPIRET _momUnlock(MomHandle mhObj);
Parameters
MomHandle mhObj
Handle of a memory object locked with _momLock().
Return

Always returns NULL.

Description

_momUnlock() is used to end access to a memory object. This function should be called as soon as the pointer to the object's data (returned by _momLock()) is no longer needed.

The unlock should always take place before the end of the function which has locked the object. Locking a memory object over a longer time span is not illegal, but should be avoided. The more objects are locked in memory the less efficient is the packing of memory, which causes fragmentation.

Since Xbase++ applications have several internal threads, the position of the data in memory can be changed at any time after the call to _momUnlock(), either by _momResize() or internal memory packing. That means the pointer returned by _momLock() can not be used after _momUnlock().

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; 

/* Warning: after the following call the value pNew is invalid */ 
_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.