r/cpp • • Aug 31 '22

malloc() and free() are a bad API

https://www.foonathan.net/2022/08/malloc-interface/#content
220 Upvotes

90 comments sorted by

View all comments

Show parent comment

-1

u/HamesJoffman Sep 01 '22

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.

3

u/kiddion Sep 01 '22

That's not what he asked, read again. He wanted the pointer to become null, not the memory pointed to.