Skip to content
Snippets Groups Projects
Commit 8af1ba2c authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Added smart pointer test in slides and in CheatSheet

parent 2314625b
No related branches found
No related tags found
No related merge requests found
......@@ -81,6 +81,14 @@ Simple example of a memory leak and how valgrind helps a lot with this.
Not so simple solution here. And the use of gdb with steping at the level of the destructor call is recommended. Give it as a hint to people.
The solution is that the wrong destructor is called when calling "delete hexa" because the constructor is not virtual while it should be.
### smartPointer
Here we have four code snippets that will benefit from using smart pointers.
* `problem1` is a simple case of usage of `make_unique` with an observer pattern where the raw pointer shoule be used.
* `problem2` is an example of a collection of pointers. Move semantic has to be used to transfer ownership of newly created objects to the container.
* `problem3` is an example of shared ownership where `std::shared_pointer` should be used.
* `problem4()` is the most difficult. Skip if not enough time. It has the same flow as the memcheck problem, that destructor should be virtual in the Base class
### callgrind
The goal is again to play. With the optimized version, it's interesting to see how much the startup time dominates the few computations done.
......
......@@ -1669,3 +1669,19 @@ of 'std::unique_ptr<Foo>'
\end{cppcode*}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitlegb{smart pointers}
\begin{alertblock}{Exercise Time}
\begin{itemize}
\item go to code/smartPointers
\item compile and run the program. It doesn't generate any output.
\item Run with valgrind to check for leaks
\begin{minted}{shell-session}
$ valgrind --leak-check=full --track-origins=yes ./smartPointers
\end{minted}
\item Go through {\ttfamily problem1()} to {\ttfamily problem3()} and fix the leaks using smart pointers.
\item {\ttfamily problem4()} is the most difficult. Skip if not enough time.
\end{itemize}
\end{alertblock}
\end{frame}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment