共用方式為


_calloc_dbg

偵錯的標頭配置之記憶體區塊,具有額外的空間堆積中的數字,並覆寫緩衝區 (偵錯版本)。

void *_calloc_dbg( 
   size_t num,
   size_t size,
   int blockType,
   const char *filename,
   int linenumber 
);

參數

  • num
    記憶體區塊的要求的數目。

  • size
    要求的每個記憶體區塊 (位元組) 的大小。

  • blockType
    要求的記憶體區塊類型: _CLIENT_BLOCK或_NORMAL_BLOCK。

    配置的區塊型別和它們的使用方式的相關資訊,請參閱類型的區塊在偵錯堆積上

  • filename
    要求配置作業的來源檔案名稱的指標或NULL。

  • linenumber
    對齊配置操作所要求的原始程式檔中的數字或NULL。

filename和linenumber參數才可以使用的時機_calloc_dbg明確地呼叫或 _CRTDBG_MAP_ALLOC 巳經定義了前置處理器常數。

傳回值

如果成功地完成,這個函式傳回指標到最後一個配置的記憶體區塊的使用者部份、 呼叫新的處理常式函式,則會傳回NULL。 傳回的行為的完整說明,請參閱 < 備註 > 一節。 如需有關如何使用新的處理常式函式的詳細資訊,請參閱 calloc 函式。

備註

_calloc_dbg偵錯版本的 calloc 函式。 當 _DEBUG 沒有定義,每次呼叫_calloc_dbg將減少以呼叫calloc。 兩者都calloc和_calloc_dbg配置num記憶體區塊以基底堆積中,但_calloc_dbg提供了數個偵錯的功能:

  • 若要測試有裂縫封鎖使用者部分的一端的緩衝區。

  • 若要追蹤特定的配置類型區塊型別參數。

  • filename/linenumber的資訊來判斷配置要求的原點。

_calloc_dbg會使用稍微多一點空間比要求每個記憶體區塊配置size。 額外的空間用於偵錯堆積管理員若要連結的偵錯記憶體區塊,並提供偵錯標頭資訊給應用程式,並覆寫緩衝區。 當配置區塊時,使用者區塊的部份填滿 0xCD 的值,而每個覆寫緩衝區會填入 0xFD。

_calloc_dbg設定errno到ENOMEM記憶體配置失敗時。 EINVAL會傳回所需的記憶體 (包括先前所述的額外負荷) 量若超過_HEAP_MAXREQ。 如需這和其他錯誤碼資訊,請參閱errno、 _doserrno、 _sys_errlist 和 _sys_nerr

如需有關如何記憶體區塊會配置、 初始化,而且在基底堆積的偵錯版本管理的資訊,請參閱記憶體管理和偵錯堆積。 呼叫應用程式的偵錯組建中的標準的堆積函式對其偵錯版本之間的差異的相關資訊,請參閱使用偵錯版本與基底版本

需求

常式

所需的標頭

_calloc_dbg

<crtdbg.h>

如需相容性資訊,請參閱相容性在簡介中。

範例

// crt_callocd.c
/*
 * This program uses _calloc_dbg to allocate space for
 * 40 long integers. It initializes each element to zero.
 */
#include <stdio.h>
#include <malloc.h>
#include <crtdbg.h>

int main( void )
{
        long *bufferN, *bufferC;

        /* 
         * Call _calloc_dbg to include the filename and line number
         * of our allocation request in the header and also so we can
         * allocate CLIENT type blocks specifically
         */
        bufferN = (long *)_calloc_dbg( 40, sizeof(long), _NORMAL_BLOCK, __FILE__, __LINE__ );
        bufferC = (long *)_calloc_dbg( 40, sizeof(long), _CLIENT_BLOCK, __FILE__, __LINE__ );
        if( bufferN != NULL && bufferC != NULL )
              printf( "Allocated memory successfully\n" );
        else
              printf( "Problem allocating memory\n" );

        /* 
         * _free_dbg must be called to free CLIENT type blocks
         */
        free( bufferN );
        _free_dbg( bufferC, _CLIENT_BLOCK );
}
  

.NET Framework 對等用法

不適用。 若要呼叫標準的 c 函式,使用PInvoke。 如需詳細資訊,請參閱平台叫用範例

請參閱

參考

偵錯常式

calloc

_malloc_dbg

_DEBUG