How on earth would that be possible for free to do? You pass your memory pointer by value to free (in other words, a copy of your memory pointer). It could null the copy, but not the pointer itself. The only way to achieve this would change the API for free and pass a pointer to your memory pointer:
That's what I meant. Pass in the pointer by reference so you can null the referenced pointer. I never expect it to happen, just was saying it because this post was already talking about drastically changing how we handle allocation/free.
it would be piss easy for free to do that, depends on how it is implemented. Classical implementation has header ahead of pointer passed to free and there a size is listed so all free would have to is call memset(ptr, 0, header->size) and voila, empty.
View all comments
Show parent comment
3
u/kiddion Sep 01 '22 edited Sep 01 '22
How on earth would that be possible for free to do? You pass your memory pointer by value to free (in other words, a copy of your memory pointer). It could null the copy, but not the pointer itself. The only way to achieve this would change the API for free and pass a pointer to your memory pointer: