Brian sabbeth smart_pointers

50 %
50 %
Information about Brian sabbeth smart_pointers

Published on March 4, 2014

Author: brianSA33ETH

Source: slideshare.net

STD::SMART POINTERS Brian Sabbeth May 9, 2013

MEMORY MANAGEMENT:

MEMORY MANAGEMENT:

MEMORY MANAGEMENT:

MEMORY MANAGEMENT:

MEMORY MANAGEMENT: Amongst so many files shared objects can become a problem for pointer related issues

MEMORY MANAGEMENT: Amongst so many files shared objects can become a problem for pointer related issues

SMART POINTERS

SMART POINTERS Simulate Pointers AbstractData types Automatic Resource Deallocation

SMART POINTERS Simulate Pointers AbstractData types Automatic Resource Deallocation

SMART POINTERS #include <memory> defines general utilities to manage dynamic memory: “They work by means of operator overloading, the behavior of traditional (raw) pointers, (e.g. dereferencing, assignment) while providing additional memory management algorithms.” ~wikipedia std::shared_ptr std::unique_ptr

STD::UNIQUE_PTR #include <memory>

STD::UNIQUE_PTR #include <memory> Unique – Not allowed to be copied! New objects can be moved or transferred between smart pointers.

STD::UNIQUE_PTR #include <memory> Unique – Not allowed to be copied! New objects can be moved or transferred between smart pointers. std::unique_ptr<int>uniqPtr 1(new int(123) );

STD::UNIQUE_PTR #include <memory> Unique – Not allowed to be copied! But can be moved. EASY TO IMPLEMENT: std::unique_ptr<int> uniqPtr1(new int(123) ); * uniqPtr1 123

STD::UNIQUE_PTR #include <memory> Unique – Not allowed to be copied! But can be moved. EASY TO IMPLEMENT: std::unique_ptr<int> uniqPtr1(new int(123) ); * uniqPtr1 123 * std::unique_ptr<int> uniqPtr2 = uniqPtr1; uniqPtr2

STD::UNIQUE_PTR #include <memory> Unique – Not allowed to be copied! But can be moved. EASY TO IMPLEMENT: std::unique_ptr<int> uniqPtr1(new int(123) ); * uniqPtr1 123 * std::unique_ptr<int> uniqPtr2 = uniqPtr1; uniqPtr2

STD::UNIQUE_PTR #include <memory> Unique – Not allowed to be copied! But can be moved. EASY TO IMPLEMENT: std::unique_ptr<int> uniqPtr1(new int(123) ); std::unique_ptr<int> uniqPtr2 = std::move(uniqPtr1); * uniqPtr1 123

STD::UNIQUE_PTR #include <memory> Unique – Not allowed to be copied! But can be moved. EASY TO IMPLEMENT: std::unique_ptr<int> uniqPtr1(new int(123) ); std::unique_ptr<int> uniqPtr2 = std::move(uniqPtr1); * uniqPtr1 123

STD::UNIQUE_PTR #include <memory> Unique – Not allowed to be copied! But can be moved. EASY TO IMPLEMENT: std::unique_ptr<int> uniqPtr1(new int(123) ); std::unique_ptr<int> uniqPtr2 = std::move(uniqPtr1); * uniqPtr1 123

STD::UNIQUE_PTR #include <memory> Unique – Not allowed to be copied! But can be moved. EASY TO IMPLEMENT: std::unique_ptr<int> uniqPtr1(new int(123) ); std::unique_ptr<int> uniqPtr2 = std::move(uniqPtr1); 123

STD::UNIQUE_PTR #include <memory> Unique – Not allowed to be copied! But can be moved. EASY TO IMPLEMENT: std::unique_ptr<int> uniqPtr1(new int(123) ); std::unique_ptr<int> uniqPtr2 = std::move(uniqPtr1); * uniqPtr2 123

STD::UNIQUE_PTR Unique Pointers are returnable EASILY DONE! std::unique_ptr<int>returnUnique(intx); { unique_ptr<int>my_unique_ptr(newint(x)); return my_unique_ptr; } This returns a local variable which will be destroyed within the function when return is read The pointer itself handles the return as if it is a “move.”

STD::SHARED_PTR #include <memory> std::shared_ptr<int> sharedPtr1(new int(123) ); * 123 sharedPtr1 1 Ref Count

STD::SHARED_PTR #include <memory> std::shared_ptr<int> sharedPtr1(new int(123) ); * 123 sharedPtr1 1 Ref Count

STD::SHARED_PTR #include <memory> std::shared_ptr<int> sharedPtr1(new int(123) ); std::shared_ptr<int> sharedPtr2(sharedPtr1); * 123 sharedPtr1 2 Ref Count

STD::SHARED_PTR #include <memory> std::shared_ptr<int> sharedPtr1(new int(123) ); * 123 sharedPtr1 1 Ref Count

STD::SHARED_PTR #include <memory> Shared! 123 0 Ref Count

STD::SHARED_PTR #include <memory> Shared! 0 Ref Count

STD::SHARED_PTR #include <memory> Memory is free

STD::SHARED_PTR

STD::SMART_POINTERS Bibliography: "Smart Pointer." Wikipedia. Wikimedia Foundation, 04 June 2013. Web. 06 May 2013. Lavavej, Stephen T. "C9 Lectures:.” Microsoft, n.d. Web. 06 May 2013. C Reference. N.p., n.d. Web. 06 May 2013.

Add a comment

Related presentations

Related pages

Brian sabbeth smart_pointers, SlideSearchEngine.com

Brian sabbeth smart_pointersby brianSA33ETH ... STD::SMART POINTERS Brian Sabbeth May 9, 2013 MEMORY MANAGEMENT: MEMORY MANAGEMENT:
Read more

Brian sabbeth smart_pointers - Documents

Brian 1. Hi. My name is Brian, Iam 13 years old 2. • My parents are Rocíoand Agustín, I have gota brother, his name isAdrián and he is 23years old.
Read more

Smart Pointers | LinkedIn

View 384 Smart Pointers posts, presentations, experts, and more. Get the professional knowledge you need on LinkedIn.
Read more