I think I've got a good grasp on how to handle memory in C++ but doing it in C is different I'm a bit off.
In C++ I've got constructors and destructors, I've got the pretty straightforward new and delete and I know how to encapsulate it using RAII, using with smart pointers and within classes.
However in C I can't handle malloc and free the same way. I don't know how to hide them and how to automate things. All I can figure is using functions for initiating and destroying my pointers. But how should I structure my memory handling?
While writing this I've realized this is more a question about me understanding the flow of C than anything else, but one question at a time.
Edit: Thanks for the answers but I need to rephrase myself.
When I say that I use RAII and smart pointers for C++ I don't want the same for C, I know it's not the same. But how I handle memory allocation in C++ is connected to these techniques.
For example in my classes I dynamically add and destroy the memory my class uses. This way I can achieve a sort of encapsulation, I don't need to know when/how/why the class handles it's memory, it just does. This means I can "hide" the lower memory handling and just focus on a few "bigger" classes.
What I want to know is what's the best-practice in handling memory in C? There are no classes with constructors/destructors to handle this for me. Is it good to allocate memory in the beginning of a function or use a function that creates it for me? And how should I free them again?
These are broad questions and they differ from situation to situation but how do you prefer to handle it? What tips and lessons can you give?