Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.


Tests a memory address to make sure it represents a currently active memory block that was allocated by the diagnostic version of new.

BOOL AfxIsMemoryBlock(
   const void* p,
   UINT nBytes,
   LONG* plRequestNumber = NULL 



Points to the block of memory to be tested.


Contains the length of the memory block in bytes.


Points to a long integer that will be filled in with the memory block's allocation sequence number, or zero if it does not represent a currently active memory block.

Nonzero if the memory block is currently allocated and the length is correct; otherwise 0.

It also checks the specified size against the original allocated size. If the function returns nonzero, the allocation sequence number is returned in plRequestNumber. This number represents the order in which the block was allocated relative to all other new allocations.

// example for AfxIsMemoryBlock
CAge* pcage = new CAge( 21 ); // CAge is derived from CObject.
ASSERT( AfxIsMemoryBlock( pcage, sizeof( CAge ) ) )

Community Additions

© 2015 Microsoft