how to convert malloc function to cpp

  1. Replace malloc with new keyword.
  2. Update the casting.
  3. Consider using smart pointers for memory management.
  4. Replace free with delete for memory deallocation.