Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a legacy C source file. it uses malloc/free functions to allocate/free memory dynamically. now I want to lift it into C++ wrapper. Shall I replace these malloc/free function with new/delete functions?

thanks a million!

What I have tried:

tried some simple demo and no problem.
Posted
Updated 1-Nov-20 11:52am
Comments
CPallini 2-Nov-20 2:13am    
Yes, and as Rick suggested, it would be even better if you replace that with smart pointers.

1 solution

Certainly. Even better would be to utilize std::unique_ptr so it is managed automatically for you. I do this when ever possible.
 
Share this answer
 
Comments
Espen Harlinn 1-Nov-20 18:28pm    
Certainly good advice :-)
CPallini 2-Nov-20 2:12am    
5.
Southmountain 3-Nov-20 11:24am    
any good article or post to share?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900