SlideShare a Scribd company logo
1 of 6
Advanced memory management
Problems with memory
            management
• Unexpected returns
• Exceptions
• Should we delete created pointer?
Smart pointers
• Pointer holder
• Smart pointer
Standard smart pointers
•   unique_ptr
•   shared_ptr
•   weak_ptr
•   auto_ptr (deprecated, do not use it)
Few simple rules
• Avoid using raw-pointers
• Use reference if user shouldn’t save passed
  object
• Use unique_ptr if your object is the only user
  of given object
• Use shared_ptr if your object should share
  given object
More rules
• Each object should have only one owner
• Owner should share resources only with it’s
  children, not with parent
• Use vector instead of dynamically allocated
  arrays

More Related Content

Viewers also liked

Viewers also liked (8)

Export management ppt
Export management pptExport management ppt
Export management ppt
 
Import,export procedure
Import,export procedureImport,export procedure
Import,export procedure
 
Export procedure
Export procedureExport procedure
Export procedure
 
EXPORT PROCEDURE & DOCUMENTATION
EXPORT PROCEDURE & DOCUMENTATIONEXPORT PROCEDURE & DOCUMENTATION
EXPORT PROCEDURE & DOCUMENTATION
 
Export Procedures and Documents
Export Procedures and DocumentsExport Procedures and Documents
Export Procedures and Documents
 
Import & export presentation
Import & export presentationImport & export presentation
Import & export presentation
 
A PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATION
A PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATIONA PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATION
A PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATION
 
EXPORT IMPORT
EXPORT IMPORTEXPORT IMPORT
EXPORT IMPORT
 

More from Amazon Web Services

More from Amazon Web Services (12)

cpp-2013 #19 Concurrency
cpp-2013 #19 Concurrencycpp-2013 #19 Concurrency
cpp-2013 #19 Concurrency
 
cpp-2013 #15 Databases
cpp-2013 #15 Databasescpp-2013 #15 Databases
cpp-2013 #15 Databases
 
cpp-2013 #14 Основи Qt
cpp-2013 #14 Основи Qtcpp-2013 #14 Основи Qt
cpp-2013 #14 Основи Qt
 
cpp-2013 #13 C++11
cpp-2013 #13 C++11cpp-2013 #13 C++11
cpp-2013 #13 C++11
 
cpp-2013 #9 STL Algorithms Part 1
cpp-2013 #9 STL Algorithms Part 1cpp-2013 #9 STL Algorithms Part 1
cpp-2013 #9 STL Algorithms Part 1
 
cpp-2013 #8 STL Containers Part 2
cpp-2013 #8 STL Containers Part 2cpp-2013 #8 STL Containers Part 2
cpp-2013 #8 STL Containers Part 2
 
cpp-2013 #7 Templates and STL Containers
cpp-2013 #7 Templates and STL Containerscpp-2013 #7 Templates and STL Containers
cpp-2013 #7 Templates and STL Containers
 
cpp-2013 #6 OOP Part 2
cpp-2013 #6 OOP Part 2cpp-2013 #6 OOP Part 2
cpp-2013 #6 OOP Part 2
 
cpp-2013 #5 File and network input/output
cpp-2013 #5 File and network input/outputcpp-2013 #5 File and network input/output
cpp-2013 #5 File and network input/output
 
cpp-2013 #3 OOP Basics
cpp-2013 #3 OOP Basicscpp-2013 #3 OOP Basics
cpp-2013 #3 OOP Basics
 
cpp-2013 #2 Organizing your code
cpp-2013 #2 Organizing your codecpp-2013 #2 Organizing your code
cpp-2013 #2 Organizing your code
 
cpp-2013 #1 C++ basics
cpp-2013 #1 C++ basicscpp-2013 #1 C++ basics
cpp-2013 #1 C++ basics
 

cpp-2013 #12 Управління пам’яттю Частина 2

  • 2. Problems with memory management • Unexpected returns • Exceptions • Should we delete created pointer?
  • 3. Smart pointers • Pointer holder • Smart pointer
  • 4. Standard smart pointers • unique_ptr • shared_ptr • weak_ptr • auto_ptr (deprecated, do not use it)
  • 5. Few simple rules • Avoid using raw-pointers • Use reference if user shouldn’t save passed object • Use unique_ptr if your object is the only user of given object • Use shared_ptr if your object should share given object
  • 6. More rules • Each object should have only one owner • Owner should share resources only with it’s children, not with parent • Use vector instead of dynamically allocated arrays