I have working in large application which contain c and cpp. The all files saved as cpp extension but the code is written in c- style. I mean it is define structure rather than
Can I use shared_ptr with malloc and free. if yes Can anyone point out me sample code base.
Yes. shared_ptr
does not allocate memory itself. However, it does delete your object once reference count drops to zero. Since it uses delete
by default and you cannot use it with objects allocated by malloc
(or any other way), you have to use a custom deleter.
if I create shared_ptr in my application and pass this pointer to another function if they are using malloc or calloc. will it impact any functionality.
It is not clear what are you asking here. If that function does not expect a shared pointer be passed, then extra care have to be taken. But it depends on what that function actually does.
We have call some function which accept double pointer and fill the structure inside their application and use malloc Can we assign those pointer to shared_ptr.
Yes, you can use any pointer with shared_ptr
.