Ok, I know this question seems to have been asked many times on stackoverflow.
but please read
Well the answer for any address is "No you can't" but the question here is to know if a pointer points to a piece of memory allocated with malloc/new.
Actually I think it could be easily implemented overriding malloc/free and keeping track of allocated memory ranges.
Do you know a memory management library providing this specific tool ?
Do you know something for production code ?
--
Valgrind is great, but it is too much instrumentation (slow) and as Will said we don't want to use Valgrind like this (making the soft crash is good enough).
Mudflap is a very good solution, but dedicated to GCC, and sadly, a check does not simply return a boolean (see my answer below).
Note that checking that memory writes are legals is a security issue. So looking for performance is motivated *.