A proof it probably cannot be usefully done:
char * p1 = malloc(1);
free( p1 );
char * p2 = malloc(1); // probably allocates same block as first malloc
Now both p1 and p2 point at same memory on heap, but only p2 is valid.
More Related Contents:
- Avoid memory leaks in C++ Pointers [closed]
- convert malloc to new c++ for struct
- In what cases do I use malloc and/or new?
- How do malloc() and free() work?
- Is it safe to delete a NULL pointer?
- How can I get the size of an array from a pointer in C?
- Dynamically allocating an array of objects
- Determine the size of a C++ array programmatically?
- What is the difference between “new” and “malloc” and “calloc” in C++? [duplicate]
- How to know if a pointer points to the heap or the stack?
- How can I get the size of a memory block allocated using malloc()? [duplicate]
- Explain this implementation of malloc from the K&R book
- Pointer-to-pointer dynamic two-dimensional array
- What happens when you deallocate a pointer twice or more in C++?
- Reason why not to have a DELETE macro for C++
- What do I need to do before deleting elements in a vector of pointers to dynamically allocated objects?
- dynamically allocated memory after program termination
- How to alloc a executable memory buffer?
- Memory allocation and deallocation across dll boundaries
- new, delete ,malloc & free
- What happen to pointers when vectors need more memory and realocate memory?
- Difference between list<Observer*>* and list<Observer*> in C++ [closed]
- When were pointers added to C / C++? [closed]
- What is the default constructor for C++ pointer?
- Why is there no reallocation functionality in C++ allocators?
- can’t modify char* – Memory access violation
- c++ delete pointer issue, can still access data [closed]
- Where ampersand “&” can be put when passing argument by reference?
- non-const pointer argument to a const double pointer parameter
- Polymorphism & Pointers to arrays [duplicate]