Compartilhar via


IMalloc (Compact 2013)

3/26/2014

This interface allocates, frees, and manages memory.

When to Implement

In general, you should not implement IMalloc, instead use the COM implementation, which is guaranteed to be thread-safe in managing task memory. You get a pointer to the COM task allocator object's IMalloc through a call to the CoGetMalloc function.

When to Use

Call the methods of IMalloc to allocate and manage memory. The COM libraries and object handlers also call the IMalloc methods to manage memory.

Object handlers should call CoGetMalloc to get a pointer to the IMalloc implementation on the task allocator object and use the implementation of those methods to manage task memory.

The IMalloc methods Alloc, Free, and Realloc are similar to the C library functions malloc, free, and realloc. For debugging, refer to the functions CoRegisterMallocSpy and CoRevokeMallocSpy.

Methods

The following table shows the methods for this interface in the order that the compiler calls the methods. Like all COM interfaces, this interface inherits the methods for the IUnknown interface.

IUnknown method

Description

QueryInterface

Returns pointers to supported interfaces.

AddRef

Increments reference count.

Release

Decrements reference count.

IMalloc method

Description

Alloc

Allocates a block of memory.

Realloc

Changes the size of a previously allocated block of memory.

Free

Frees a previously allocated block of memory.

GetSize

Returns the size in bytes of a previously allocated block of memory.

DidAlloc

Determines whether this instance of IMalloc was used to allocate the specified block of memory.

HeapMinimize

Minimizes the heap by releasing unused memory to the operating system.

Remarks

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

Requirements

Header

objidl.h,
objidl.idl

Library

ole32.lib

See Also

Reference

COM Interfaces
CoGetMalloc
CoRegisterMallocSpy
CoRevokeMallocSpy
IMallocSpy