Commit 0ea59156 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

Add a paragraph about smart pointers efficiency, citing the reference given in MR29.

parent 986475fb
...@@ -561,6 +561,23 @@ ...@@ -561,6 +561,23 @@
"This simplifies the reading, especially if templates are also involved... " "This simplifies the reading, especially if templates are also involved... "
] ]
}, },
"cell_type": "markdown",
"metadata": {},
"source": [
"## The cost of using smart pointers\n",
"This [article]( provides an analysis of the cost involved both in performance and memory when using a smart pointer. To put in the nutshell, its conclusions are:\n",
"- `std::unique_ptr` bears no overhead in memory (except in a very edge case you can safely ignore for now) and little overhead in performance, at least for the latter when compiler optimizations are enabled (we will talk about them in a later [notebook](../6-InRealEnvironment/3-Compilers.ipynb)).\n",
"- `std::shared_ptr` incurs a memory overhead (to keep the reference count) and a performance overhead as well (which is partially mitigated if the memory was allocated through `std::make_shared`). The performance overhead is especially important when no optimizations are involved.\n",
"This highlights once more what we said earlier:\n",
"- Use smart pointers: RAII is simply too precious to manage properly your ressources!\n",
"- Use `std::unique_ptr` wherever you can, and use `std::shared_ptr` when you really need several instances of the same ressource.\n"
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
...@@ -628,5 +645,5 @@ ...@@ -628,5 +645,5 @@
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 2 "nbformat_minor": 4
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment