Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function changes the size of a previously allocated block of task memory.

Syntax

LPVOID CoTaskMemRealloc(
  LPVOID 
pv, 
  ULONG 
cb
); 

Parameters

pv

[in] Void pointer to the memory block to be reallocated. It can be a NULL pointer, as discussed in the Remarks.

cb

[in] Size, in bytes, of the memory block to be reallocated. It can be zero, as discussed in the following Remarks.

Return Value

A pointer to the reallocated memory block indicates success. NULL indicates insufficient memory, or that cbis zero and pvis not NULL.

Remarks

The pvargument points to the beginning of the memory block. If pvis NULL, CoTaskMemReallocallocates a new memory block in the same way as the CoTaskMemAllocfunction. If pvis not NULL, it should be a pointer returned by a prior call to CoTaskMemAlloc.

The cbargument specifies the size (in bytes) of the new block. The contents of the block are unchanged up to the shorter of the new and old sizes, although the new block can be in a different location. Because the new block can be in a different memory location, the pointer returned by CoTaskMemReallocis not guaranteed to be the pointer passed through the pvargument. If pvis not NULL and cbis zero, then the memory pointed to by pvis freed.

CoTaskMemReallocreturns a void pointer to the reallocated (and possibly moved) memory block. The return value is NULL if the size is zero and the buffer argument is not NULL, or if there is not enough memory available to expand the block to the given size. In the first case, the original block is freed; in the second, the original block is unchanged.

The storage space pointed to by the return value is guaranteed to be suitably aligned for storage of any type of object. To get a pointer to a type other than void, use a type cast on the return value.

Passing into this function any invalid and, under some circumstances, NULL pointers result in unexpected termination of the application.

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

Requirements

Header objbase.h
Library ole32.lib
Windows Embedded CE Windows CE 2.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

CoTaskMemAlloc