Jump to content

wpAllocMem

From EDM2

This instance method is called to allocate memory for use by an object.

Syntax

_wpAllocMem(somSelf, cbBytes, prc)

Parameters

somSelf (WPObject *) - input
Pointer to the object on which the method is being invoked.
Points to an object of class WPObject.
cbBytes (ULONG) - in/out
Specifies the size, in bytes, of memory required.
prc (PULONG) - in/out
Pointer to error code.
NULL: If an error occurs, the system displays an appropriate message.
prc: If an error occurs, one of the following is returned in prc:
6: ERROR_INVALID_HANDLE
8: ERROR_NOT_ENOUGH_MEMORY
95: ERROR_INTERRUPT
103: ERROR_TOO_MANY_SEM_REQUESTS
105: ERROR_SEM_OWNER_DIED
640: ERROR_TIMEOUT

Returns

pbNewMem (PBYTE) - returns
Success indicator.
NULL: Memory allocation failed.
Other: A pointer to the newly allocated memory.

Remarks

Memory allocated by wpAllocMem should be de-allocated when it is no longer needed by calling wpFreeMem. Allocated memory not cleaned up by an object is de-allocated automatically when the object is no longer in use. This method does not zerofill the allocated memory.

Usage

This method can be called at any time to allocate memory to be used for this object only.

How to Override

This method should be overridden if a substitute memory allocation facility is to be used. Object classes overriding this method should also override wpFreeMem.

Example Code

This example initializes state variables and allocates any extra memory needed.

SOM_Scope void SOMLINK myf_wpInitData(MYFILE *somSelf)
{
    MYFILEData *somThis = MYFILEGetData(somSelf);
    MYFILEMethodDebug("MYFILE","myf_wpInitData");

    parent_wpInitData(somSelf);    /* Have parent method do initialization */

    _pszLastWorker = (PSZ) _wpAllocMem(somSelf,
                                       CCHMAXPATH+1,  /* Number of bytes */
                                       NULL);        /* Return error message */

    if (_pszLastWorker) {

      strcpy(_pszLastWorker, DEFAULT_LASTWORKER);

    } /* endif */

}

Related Methods