_expand_dbg

只要展開或縮小的區塊 (偵錯版本) 可調整大小的記憶體堆積中指定的區塊。

void *_expand_dbg( 
   void *userData,
   size_t newSize,
   int blockType,
   const char *filename,
   int linenumber 
);

參數

  • userData
    在先前配置的記憶體區塊的指標。

  • newSize
    要求新的大小 (以位元組為單位) 的區塊。

  • blockType
    要求已調整大小的區塊類型: _CLIENT_BLOCK 或_NORMAL_BLOCK。

  • filename
    要求的原始程式檔名稱的指標展開作業或NULL。

  • linenumber
    行號,展開作業所要求的原始程式檔中或NULL。

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

傳回值

如果成功地完成, _expand_dbg傳回已調整大小的記憶體區塊的指標。不會移動記憶體,因為地址等同於保留使用者資料。如果發生錯誤,或是封鎖無法展開至所要求的大小,則會傳回NULL。發生故障時, errno是從作業系統性質的資訊失敗。如需 errno 的詳細資訊,請參閱 errno、 _doserrno、 _sys_errlist 和 _sys_nerr

備註

_expand_dbg 函式是 _ 偵錯版本展開函式。當 _DEBUG 沒有定義,每次呼叫_expand_dbg 將減少以呼叫_expand。兩者都_expand 和_expand_dbg 調整 「 基底的堆集 」 中的記憶體區塊的大小,但_expand_dbg可容納多個偵錯的功能: 任一邊的使用者區塊的部份若要測試是否有裂縫,來追蹤特定的配置類型的區塊型別參數的緩衝區和filename/linenumber資訊來判斷配置要求的原點。

_expand_dbg調整指定的記憶體區塊,具有比要求稍微多一點空間newSize。newSize可能是大於或小於原本已配置的記憶體區塊的大小。額外的空間用於偵錯堆積管理員若要連結的偵錯記憶體區塊,並提供偵錯標頭資訊給應用程式,並覆寫緩衝區。調整大小作業被透過 [展開] 或 [低於原始的記憶體區塊。_expand_dbg不會移動記憶體區塊,並不會如 _realloc_dbg 函式。

當newSize已超過記憶體區塊的大小會展開原始區塊。放大,如果記憶體區塊無法展開以容納要求的大小,在NULL會傳回。當newSize會少於原始區塊取得新的大小之前,記憶體區塊的大小都感染。

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

這個函式會驗證它的參數。如果memblock是空值的指標,或如果大小大於_HEAP_MAXREQ,如所述,這個函式叫用不正確的參數處理常式中, 參數驗證。如果要繼續,請允許執行errno設定為 [ EINVAL ,則函數會傳回NULL。

需求

常式

所需的標頭

_expand_dbg

<crtdbg.h>

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

文件庫

偵錯版本的 C 執行階段程式庫只。

範例

// crt_expand_dbg.c
//
// This program allocates a block of memory using _malloc_dbg
// and then calls _msize_dbg to display the size of that block.
// Next, it uses _expand_dbg to expand the amount of
// memory used by the buffer and then calls _msize_dbg again to
// display the new amount of memory allocated to the buffer.
//

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <crtdbg.h>

int main( void )
{
   long *buffer;
   size_t size;

   // Call _malloc_dbg to include the filename and line number
   // of our allocation request in the header
   buffer = (long *)_malloc_dbg( 40 * sizeof(long),
                                 _NORMAL_BLOCK, __FILE__, __LINE__ );
   if( buffer == NULL )
      exit( 1 );

   // Get the size of the buffer by calling _msize_dbg
   size = _msize_dbg( buffer, _NORMAL_BLOCK );
   printf( "Size of block after _malloc_dbg of 40 longs: %u\n", size );

   // Expand the buffer using _expand_dbg and show the new size
   buffer = (long *)_expand_dbg( buffer, size + sizeof(long),
                                 _NORMAL_BLOCK, __FILE__, __LINE__ );

   if( buffer == NULL )
      exit( 1 );
   size = _msize_dbg( buffer, _NORMAL_BLOCK );
   printf( "Size of block after _expand_dbg of 1 more long: %u\n",
           size );

   free( buffer );
   exit( 0 );
}
  

註解

這個程式的輸出,取決於您的電腦能夠展開所有的區段。如果所有的區段已經展開,輸出會反映在 [輸出] 區段中。

.NET Framework 對等用法

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

請參閱

參考

偵錯常式

_malloc_dbg