最近發現CRT控制臺程序沒有TRACE和內存溢出檢查,很郁悶。無聊中翻看MSDN的Memory Management and the Debug Heap篇,發現C的Debug版本用_malloc_dbg代替malloc,而_malloc_dbg者給數據堆加上一個控制頭組成鏈表,方便記錄溢出。原話如下: When you request a memory block, the debug heap manager allocates from the base
heap a slightly larger block of memory than requested and returns a pointer to
your portion of that block. For example, suppose your application contains the
call: malloc( 10 ). In a release build, malloc would call the base heap allocation routine
requesting an allocation of 10 bytes. In a debug build, however, malloc
would call _malloc_dbg, which would then call
the base heap allocation routine requesting an allocation of 10 bytes plus
approximately 36 bytes of additional memory. All the resulting memory blocks in
the debug heap are connected in a single linked list, ordered according to when
they were allocated:
那個控制頭的數據結構如下:
typedef struct _CrtMemBlockHeader { // Pointer to the block allocated just before this one: struct _CrtMemBlockHeader *pBlockHeaderNext; // Pointer to the block allocated just after this one: struct _CrtMemBlockHeader *pBlockHeaderPrev; char*szFileName; // File name int nLine; // Line number size_t nDataSize; // Size of user block int nBlockUse; // Type of block long lRequest; // Allocation number // Buffer just before (lower than) the user's memory: unsigned char gap[nNoMansLandSize]; } _CrtMemBlockHeader;
1、Selects (adds a check mark to) a given radio button in a group and clears
(removes a check mark from) all other radio buttons in the group.
在IDC_SERVER1-IDC_SERVER10中選中wServer的ID,有點像分組。
DialogBoxParam (hInst, TEXT ("Servers"), hwnd, ServerDlg, (LPARAM) szIPAddr);
On the first call to strtok , the function skips leading delimiters and
returns a pointer to the first token in strToken , terminating the token
with a null character. More tokens can be broken out of the remainder of
strToken by a series of calls to strtok . Each call to
strtok modifies strToken by inserting a null character after the
token returned by that call. To read the next token from strToken , call
strtok with a NULL value for the strToken argument. The
NULL strToken argument causes strtok to search for the next
token in the modified strToken . The strDelimit argument can take
any value from one call to the next so that the set of delimiters may vary.
Warning Each of these functions uses a static
variable for parsing the string into tokens. If multiple or simultaneous calls
are made to the same function, a high potential for data corruption and
inaccurate results exists. Therefore, do not attempt to call the same function
simultaneously for different strings and be aware of calling one of these
function from within a loop where another routine may be called that uses the
same function. However, calling this function simultaneously from multiple
threads does not have undesirable effects.