Share via


IMallocSpy::PreAlloc

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

This method is called just prior to invoking the IMalloc::Alloc method.

Syntax

ULONG PreAlloc(
  ULONG cbRequest 
);

Parameters

  • cbRequest
    [in] Number of bytes specified in the allocation request the caller is passing to IMalloc::Alloc.

Return Value

The byte count actually passed to IMalloc::Alloc, which should be greater than or equal to the value of cbRequest.

Remarks

The IMallocSpy::PreAlloc implementation may extend or modify the allocation to store debug-specific information with the allocation.

PreAlloc can force memory allocation failure by returning zero, allowing testing to ensure that the application handles allocation failure gracefully in all cases. In this case, IMallocSpy::PostAlloc is not called and IMalloc::Alloc returns NULL.

Forcing allocation failure is effective only if cbRequest is not equal to zero.

If PreAlloc is forcing failure by returning NULL, PostAlloc is not called. However, if IMalloc::Alloc encounters a real memory failure and returns NULL, PostAlloc is called.

The call to PreAlloc through the return from PostAlloc is guaranteed to be thread-safe.

To determine whether the platform supports this interface, see Determining Supported COM APIs.

Requirements

Header objidl.h, objidl.idl
Library ole32.lib
Windows Embedded CE Windows CE 3.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

IMalloc::Alloc
IMallocSpy::PostAlloc
CoRegisterMallocSpy
CoRevokeMallocSpy