Pointer is allocated on the stack and the object it is pointing to is allocated on the heap.
Memory is allocated when a pointer is defined. A reference however, is a name alias & hence no memory is allocated for it( Is it correct? ). 2. Reference is bound to be initialized at the time of definition because, a reference is implemented with a constant pointer & hence cannot be made to point to the other object.
(And, yes, if you pull out a plate from somewhere with the stack, you will probably break something.) There are two fundamental operations on a stack: push data-item. This causes the data-item to be placed on the top of the stack and moves the stack pointer to point to this latest item.
I want to know if a pointer points to a piece of memory allocated with malloc/new. I realize that the answer for an arbitrary address is "No you can't" but I do think it is possible to override malloc/free and keep 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 legal is a security issue. So looking for performance is motivated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With