Skip to content

Commit 69059e3

Browse files
authored
Merge pull request #2318 from changeworld/patch-1
Delete unnecessary spaces
2 parents a3228fb + b7f05f8 commit 69059e3

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

docs/debugger/allocation-hooks-and-c-run-time-memory-allocations.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
title: "Allocation Hooks and C Run-Time Memory Allocations | Microsoft Docs"
33
ms.date: "11/04/2016"
44
ms.topic: "conceptual"
5-
f1_keywords:
5+
f1_keywords:
66
- "vs.debug.hooks"
7-
dev_langs:
7+
dev_langs:
88
- "CSharp"
99
- "VB"
1010
- "FSharp"
1111
- "C++"
12-
helpviewer_keywords:
12+
helpviewer_keywords:
1313
- "debugging [C++], hook functions"
1414
- "memory allocation, troubleshooting allocation hooks"
1515
- "allocation hooks"
@@ -18,20 +18,20 @@ ms.assetid: cc34ee96-3d91-41bd-a019-aa3759139e7e
1818
author: "mikejo5000"
1919
ms.author: "mikejo"
2020
manager: jillfra
21-
ms.workload:
21+
ms.workload:
2222
- "multiple"
2323
---
2424
# Allocation Hooks and C Run-Time Memory Allocations
25-
A very important restriction on allocation hook functions is that they must explicitly ignore `_CRT_BLOCK` blocks. These blocks are the memory allocations made internally by C run-time library functions if they make any calls to C run-time library functions that allocate internal memory. You can ignore `_CRT_BLOCK` blocks by including the following code at the beginning of your allocation hook function:
26-
25+
A very important restriction on allocation hook functions is that they must explicitly ignore `_CRT_BLOCK` blocks. These blocks are the memory allocations made internally by C run-time library functions if they make any calls to C run-time library functions that allocate internal memory. You can ignore `_CRT_BLOCK` blocks by including the following code at the beginning of your allocation hook function:
26+
2727
```cpp
28-
if ( nBlockUse == _CRT_BLOCK )
29-
return( TRUE );
30-
```
31-
32-
If your allocation hook doesn't ignore `_CRT_BLOCK` blocks, then any C run-time library function called in your hook can trap the program in an endless loop. For example, `printf` makes an internal allocation. If your hook code calls `printf`, then the resulting allocation will cause your hook to be called again, which will call **printf** again, and so on, until the stack overflows. If you need to report `_CRT_BLOCK` allocation operations, one way to circumvent this restriction is to use Windows API functions, rather than C run-time functions, for formatting and output. Because the Windows APIs don't use the C run-time library heap, they won't trap your allocation hook in an endless loop.
33-
34-
If you examine the run-time library source files, you will see that the default allocation hook function, **CrtDefaultAllocHook** (which simply returns **TRUE**), is located in a separate file of its own, DBGHOOK.C. If you want your allocation hook to be called even for the allocations made by the run-time startup code that is executed before your application's **main** function, you can replace this default function with one of your own, instead of using [_CrtSetAllocHook](/cpp/c-runtime-library/reference/crtsetallochook).
35-
36-
## See Also
37-
[Debug Hook Function Writing](../debugger/debug-hook-function-writing.md)
28+
if ( nBlockUse == _CRT_BLOCK )
29+
return( TRUE );
30+
```
31+
32+
If your allocation hook doesn't ignore `_CRT_BLOCK` blocks, then any C run-time library function called in your hook can trap the program in an endless loop. For example, `printf` makes an internal allocation. If your hook code calls `printf`, then the resulting allocation will cause your hook to be called again, which will call **printf** again, and so on, until the stack overflows. If you need to report `_CRT_BLOCK` allocation operations, one way to circumvent this restriction is to use Windows API functions, rather than C run-time functions, for formatting and output. Because the Windows APIs don't use the C run-time library heap, they won't trap your allocation hook in an endless loop.
33+
34+
If you examine the run-time library source files, you will see that the default allocation hook function, **CrtDefaultAllocHook** (which simply returns **TRUE**), is located in a separate file of its own, DBGHOOK.C. If you want your allocation hook to be called even for the allocations made by the run-time startup code that is executed before your application's **main** function, you can replace this default function with one of your own, instead of using [_CrtSetAllocHook](/cpp/c-runtime-library/reference/crtsetallochook).
35+
36+
## See Also
37+
[Debug Hook Function Writing](../debugger/debug-hook-function-writing.md)

0 commit comments

Comments
 (0)