Debugversionen von HeapreservierungsfunktionenDebug Versions of Heap Allocation Functions
Die C-Laufzeitbibliothek umfasst spezielle Debugversionen der Heapreservierungsfunktionen.The C run-time library contains special Debug versions of the heap allocation functions. Diese Funktionen haben dieselben Namen wie die Releaseversionen, gefolgt vom Suffix _dbg.These functions have the same names as the Release versions with _dbg appended to them. In diesem Thema werden die Unterschiede zwischen der Releaseversion und der _dbg-Version einer CRT-Funktion beschrieben, wobei malloc
und _malloc_dbg
als Beispiele verwendet werden.This topic describes the differences between the Release version of a CRT function and the _dbg version, using malloc
and _malloc_dbg
as examples.
Wenn _DEBUG definiert ist, ordnet die CRT alle malloc -Aufrufe _malloc_dbgzu.When _DEBUG is defined, the CRT maps all malloc calls to _malloc_dbg. Aus diesem Grund müssen Sie den Code nicht umschreiben, indem Sie _malloc_dbg
durch malloc
ersetzen, um die Vorteile beim Debuggen nutzen zu können.Therefore, you do not need to rewrite your code using _malloc_dbg
instead of malloc
to receive the benefits while debugging.
Unter Umständen möchten Sie _malloc_dbg
jedoch explizit aufrufen.You might want to call _malloc_dbg
explicitly, however. Der explizite Aufruf von _malloc_dbg
bietet zusätzliche Vorteile:Calling _malloc_dbg
explicitly has some added benefits:
Nachverfolgen von
_CLIENT_BLOCK
-Reservierungen.Tracking_CLIENT_BLOCK
type allocations.Speichern von Quelldatei und Zeilennummer an der Stelle, an der die Reservierung angefordert wurde.Storing the source file and line number where the allocation request occurred.
Wenn Sie Ihre
malloc
Aufrufe nicht in_malloc_dbg
konvertieren möchten, können Sie die Quelldatei Informationen abrufen, indem Sie _CRTDBG_MAP_ALLOCdefinieren, wodurch der Präprozessor alle Aufrufe vonmalloc
direkt den_malloc_dbg
zuordnet, anstatt sich auf einen Wrapper zu verlassen.malloc
.If you do not want to convert yourmalloc
calls to_malloc_dbg
, you can obtain the source file information by defining _CRTDBG_MAP_ALLOC, which causes the preprocessor to directly map all calls tomalloc
to_malloc_dbg
instead of relying on a wrapper aroundmalloc
.Um Reservierungstypen in Clientblöcken gesondert nachzuverfolgen, muss
_malloc_dbg
direkt aufgerufen und derblockType
-Parameter auf_CLIENT_BLOCK
festgelegt werden.To track the separate types of allocations in client blocks, you must call_malloc_dbg
directly and set theblockType
parameter to_CLIENT_BLOCK
.Wenn _DEBUG nicht definiert ist, werden Aufrufe von
malloc
nicht gestört, Aufrufe_malloc_dbg
werden zumalloc
aufgelöst, die Definition von _CRTDBG_MAP_ALLOC wird ignoriert, und es werden keine Quelldatei Informationen zur Zuordnungs Anforderung bereitgestellt.When _DEBUG is not defined, calls tomalloc
are not disturbed, calls to_malloc_dbg
are resolved tomalloc
, the definition of _CRTDBG_MAP_ALLOC is ignored, and source file information pertaining to the allocation request is not provided. Damalloc
keinen Blocktypparameter hat, werden_CLIENT_BLOCK
-Anforderungen wie Standardreservierungen behandelt.Becausemalloc
does not have a block type parameter, requests for_CLIENT_BLOCK
types are treated as standard allocations.
Siehe auchSee also
Feedback
Feedback wird geladen...