MemCheckPtr should only be used on memory allocated with VO MemAlloc. Each time VO Allocates memory it adds a some memory before and after the block that you allocate:
[ 12 Bytes Header][ Memory Block Asked for by you] [ 4 Bytes Footer]
variable----------^
The variable that gets returned to you points to the 13th byte of the actual block that was allocated.
The header contains a 'magic number' (0x4244504a), the memory group number (see the MemGrp..() functions for more about memory groups) and the length of the block.
The Footer also has a magic number (0x44415441)
MemCheckPtr checks to see:
- If the magic number in the header is correct
- If the size that you pass it matches the size in the header
- If the magic number in the footer is correct.
Here's the sample from the VO helpfile for completeness:
ptrV := MemAlloc(100)
? MemCheckPtr(ptrV, 100) // TRUE
If you want to validate non-vo memory you can use the following API functions:
IsBadReadPtr() http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/isbadreadptr.asp
IsBadWritePtr() http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/isbadwriteptr.asp
Both functions require that you know the length of the memory block.
I hope this helps.