Memory Management and RAII

Why should you even care about memory management ?

Old school memory management

{
// some instructions
std::unique_ptr<int> smart(new int(4));
// some other operations
}
struct MyClass{
MyClass(float value) : smart(new float(value)) {}
std::unique_ptr<float> smart;
};
//....
{
MyClass objectWithSmartPointer (5.0f);
}
{
// some instructions
auto smart = std::make_unique<int>(4);
// some other operations
}
auto smart = std::make_shared<int>(4);
auto otherSmart = smart;

What about “regular” pointer then ?

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store