+ 1
What happens to heap in case of shared_ptr
Hi I have overloaded new operator to observe allocation on heap. Please find attached code for same. https://code.sololearn.com/cCMGLKJyGjfd When object of shared_ptr is created for int type, it is expected to allocate 4 bytes on heap . Why another allocation of 24 bytes is done?
1 Antwort
+ 6
The additional 24 bytes are the allocation of the shared_ptr's control block, which stores all information necessary to manage its pointer correctly. See the following link for more information (needs some scrolling down the site):
https://en.cppreference.com/w/cpp/memory/shared_ptr