Function _momLock() Foundation

Fixes a memory object for access and returns the pointer to the data.

Syntax
BYTE *_momLock(MomHandle mhObj);
Parameters
MomHandle mhObj
Handle of a memory object created with _momAlloc(), whose memory area is to be accessed.
Return

Pointer to the first byte of the memory object.

Description

_momLock() is used to access the data of a memory object. As long as a memory object is not locked, its position in memory can be changed by _momResize() or at any time by internal memory packing. The call to _momLock() prevents moving of the object. The data of the memory object can be read and changed via the returned pointer.

_momLock() also coordinates access of several threads to a memory object. If an object is locked from a different thread, _momLock()waits until _momUnlock() is called and then locks the object for this individual thread.

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; 

/* Note: after the following call the value of 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.