Skip to content

Repo sync for protected CLA branch #3659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions docs/atl/reference/ccomheap-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@ f1_keywords: ["CComHeap", "ATLCOMMEM/ATL::CComHeap", "ATLCOMMEM/ATL::CComHeap::A
helpviewer_keywords: ["CComHeap class"]
ms.assetid: c74183ce-98ae-46fb-b186-93ea4cf0222b
---
# CComHeap Class
# `CComHeap` Class

This class implements [IAtlMemMgr](../../atl/reference/iatlmemmgr-class.md) using the COM memory allocation functions.
This class implements [`IAtlMemMgr`](../../atl/reference/iatlmemmgr-class.md) using the COM memory allocation functions.

> [!IMPORTANT]
> This class and its members cannot be used in applications that execute in the Windows Runtime.

## Syntax

```
```cpp
class CComHeap : public IAtlMemMgr
```

## Members

### Public Methods
### Public methods

|Name|Description|
|----------|-----------------|
|[CComHeap::Allocate](#allocate)|Call this method to allocate a block of memory.|
|[CComHeap::Free](#free)|Call this method to free a block of memory allocated by this memory manager.|
|[CComHeap::GetSize](#getsize)|Call this method to get the allocated size of a memory block allocated by this memory manager.|
|[CComHeap::Reallocate](#reallocate)|Call this method to reallocate memory allocated by this memory manager.|
|[`CComHeap::Allocate`](#allocate)|Call this method to allocate a block of memory.|
|[`CComHeap::Free`](#free)|Call this method to free a block of memory allocated by this memory manager.|
|[`CComHeap::GetSize`](#getsize)|Call this method to get the allocated size of a memory block allocated by this memory manager.|
|[`CComHeap::Reallocate`](#reallocate)|Call this method to reallocate memory allocated by this memory manager.|

## Remarks

`CComHeap` implements memory allocation functions using the COM allocation functions, including [CoTaskMemAlloc](/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemalloc), [CoTaskMemFree](/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemfree), [IMalloc::GetSize](/windows/win32/api/objidlbase/nf-objidlbase-imalloc-getsize), and [CoTaskMemRealloc](/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemrealloc). The maximum amount of memory that can be allocated is equal to INT_MAX (2147483647) bytes.
`CComHeap` implements memory allocation functions using the COM allocation functions, including [`CoTaskMemAlloc`](/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemalloc), [`CoTaskMemFree`](/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemfree), [`IMalloc::GetSize`](/windows/win32/api/objidlbase/nf-objidlbase-imalloc-getsize), and [`CoTaskMemRealloc`](/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemrealloc). The maximum amount of memory that can be allocated is equal to `INT_MAX` (2147483647) bytes.

## Example

See the example for [IAtlMemMgr](../../atl/reference/iatlmemmgr-class.md).
See the example for [`IAtlMemMgr`](../../atl/reference/iatlmemmgr-class.md).

## Inheritance Hierarchy
## Inheritance hierarchy

`IAtlMemMgr`

Expand All @@ -52,95 +52,95 @@ See the example for [IAtlMemMgr](../../atl/reference/iatlmemmgr-class.md).

Call this method to allocate a block of memory.

```
```cpp
virtual __declspec(allocator) void* Allocate(size_t nBytes) throw();
```

### Parameters

*nBytes*<br/>
*`nBytes`*\
The requested number of bytes in the new memory block.

### Return Value
### Return value

Returns a pointer to the start of the newly allocated memory block.

### Remarks

Call [CComHeap::Free](#free) or [CComHeap::Reallocate](#reallocate) to free the memory allocated by this method.
Call [`CComHeap::Free`](#free) or [`CComHeap::Reallocate`](#reallocate) to free the memory allocated by this method.

Implemented using [CoTaskMemAlloc](/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemalloc).
Implemented using [`CoTaskMemAlloc`](/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemalloc).

## <a name="free"></a> CComHeap::Free

Call this method to free a block of memory allocated by this memory manager.

```
```cpp
virtual void Free(void* p) throw();
```

### Parameters

*p*<br/>
*`p`*\
Pointer to memory previously allocated by this memory manager. NULL is a valid value and does nothing.

### Remarks

Implemented using [CoTaskMemFree](/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemfree).
Implemented using [`CoTaskMemFree`](/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemfree).

## <a name="getsize"></a> CComHeap::GetSize

Call this method to get the allocated size of a memory block allocated by this memory manager.

```
```cpp
virtual size_t GetSize(void* p) throw();
```

### Parameters

*p*<br/>
*`p`*\
Pointer to memory previously allocated by this memory manager.

### Return Value
### Return value

Returns the size of the allocated memory block in bytes.

### Remarks

Implemented using [IMalloc::GetSize](/windows/win32/api/objidlbase/nf-objidlbase-imalloc-getsize).
Implemented using [`IMalloc::GetSize`](/windows/win32/api/objidlbase/nf-objidlbase-imalloc-getsize).

## <a name="reallocate"></a> CComHeap::Reallocate

Call this method to reallocate memory allocated by this memory manager.

```
```cpp
virtual __declspec(allocator) void* Reallocate(void* p, size_t nBytes) throw();
```

### Parameters

*p*<br/>
*`p`*\
Pointer to memory previously allocated by this memory manager.

*nBytes*<br/>
*`nBytes`*\
The requested number of bytes in the new memory block.

### Return Value
### Return value

Returns a pointer to the start of the newly allocated memory block.

### Remarks

Call [CComHeap::Free](#free) to free the memory allocated by this method.
Call [`CComHeap::Free`](#free) to free the memory allocated by this method.

Implemented using [CoTaskMemRealloc](/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemrealloc).
Implemented using [`CoTaskMemRealloc`](/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemrealloc).

## See also

[DynamicConsumer Sample](../../overview/visual-cpp-samples.md)<br/>
[Class Overview](../../atl/atl-class-overview.md)<br/>
[CWin32Heap Class](../../atl/reference/cwin32heap-class.md)<br/>
[CLocalHeap Class](../../atl/reference/clocalheap-class.md)<br/>
[CGlobalHeap Class](../../atl/reference/cglobalheap-class.md)<br/>
[CCRTHeap Class](../../atl/reference/ccrtheap-class.md)<br/>
[IAtlMemMgr Class](../../atl/reference/iatlmemmgr-class.md)
[DynamicConsumer Sample](../../overview/visual-cpp-samples.md)\
[Class Overview](../../atl/atl-class-overview.md)\
[`CWin32Heap` Class](../../atl/reference/cwin32heap-class.md)\
[`CLocalHeap` Class](../../atl/reference/clocalheap-class.md)\
[`CGlobalHeap` Class](../../atl/reference/cglobalheap-class.md)\
[`CCRTHeap` Class](../../atl/reference/ccrtheap-class.md)\
[`IAtlMemMgr` Class](../../atl/reference/iatlmemmgr-class.md)