AfxIsValidAddress 测试内存地址

转载

Tests any memory address to ensure that it is contained entirely within the program's memory space.

测试任何内存地址,以确保它是完全包含在程序的内存空间。

BOOL AfxIsValidAddress(
   const void* lp,
   UINT nBytes,
   BOOL bReadWrite = TRUE 
); 
 

Parameters

lp

Points to the memory address to be tested.

指向被测试内存。

nBytes

Contains the number of bytes of memory to be tested.

包含被测试内存的字节个数。

bReadWrite

Specifies whether the memory is both for reading and writing (TRUE) or just reading (FALSE).

确定被测试内存是读写形式(真)还是只读形式(假)。


Return Value

In debug builds, nonzero if the specified memory block is contained entirely within the program's memory space; otherwise 0.

在调试版,如果指定的内存被完全包含在程序的内存空间,返回值不为0,否则为0.

In non-debug builds, nonzero if lp is not NULL; otherwise 0.

在调试构建,如果lp不为空,返回值不为0,否则返回值为0.
 

Remarks

The address is not restricted to blocks allocated by new.

地址不仅限于模块分配新的地址。
 

Example

// Allocate a 5 character array, which should have a valid memory address.
char* arr = new char[5];

// Create a null pointer, which should be an invalid memory address.
char* null = (char*)0x0;

ASSERT(AfxIsValidAddress(arr, 5));
ASSERT(!AfxIsValidAddress(null, 5));


Requirements

Header: afx.h


AfxIsValidAddress

分享到:
评论加载中,请稍后...
创APP如搭积木 - 创意无限,梦想即时!
回到顶部