Application-defined memory deallocation callback function that replaces the default memory deallocator.
void XMemFree(
PVOID lpAddress,
ULONGLONG dwAttributes
)
lpAddress
Type: PVOID
[in] Address of the memory to be freed.
dwAttributes
Type: ULONGLONG
[in] Attributes of the allocation. Refer to XALLOC_ATTRIBUTES.
It’s important that the dwAttributes parameter’s value matches that which was passed in with the original call to XMemAlloc. (Whether this value is cached by your code, or synthesized as necessary is up to your implementation).
Consider a scenario where your underlying allocator allocates contiguous 16-byte blocks aligned on a 16-byte boundary, but you ask for a 64-byte aligned block of 128 bytes—similar, in fact, to the CRT heap if the small-object allocator is turned off.
To service this request, the allocator may in fact allocate more than 128-bytes, so that it can align the address for you. When doing so, it might store the length of the block and the actual start address of the unaligned block in the 16-byte block before the address it gives you back. The only way to determine correctly whether this was the case is to have the full information from the dwAttributes parameter to identify which allocator was used, and to correctly follow the chain back to the actual start of the allocated block.
Not matching dwAttributes could lead to corruption, memory leaks, or otherwise bad behavior.
Header: Declared in xmem.h.