IMalloc Interface
IMalloc Interface

Allocates, frees, and manages memory.

When To Implement

Generally, you should not implement IMalloc, instead using 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 IMalloc interface inherits the methods of the IUnknown interface.

In addition, IMalloc defines the following methods.

MethodDescription

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

Retrieves the size of a previously allocated block of memory.

DidAlloc

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

HeapMinimize

Minimizes the heap as much as possible by releasing unused memory to the operating system, coalescing adjacent free blocks, and committing free pages.

 

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderObjIdl.h
IDLObjIdl.idl
IIDIID_IMalloc is defined as 00000002-0000-0000-C000-000000000046

See Also

CoGetMalloc
CoRegisterMallocSpy
CoRevokeMallocSpy
IMallocSpy

Send comments about this topic to Microsoft

Build date: 11/12/2009

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View