title: Memory management patterns in C++
body: <p>I think I have a considerable experience with normal (functional) designed patters, as described e.g. in <a href="http://www.amazon.co.uk/Design-patterns-elements-reusable-object-oriented/dp/0201633612" rel="nofollow noreferrer">the gang of four book</a>, which I mainly used in java and C#. In these "managed" languages this is pretty much everything you need to know to get your work done.</p>
  
  <p>However, in C++ world the developer also has the control of how all the objects get allocated, passed around and deleted. I understand the principles (I read <a href="https://rads.stackoverflow.com/amzn/click/com/0201889544" rel="nofollow noreferrer" rel="nofollow noreferrer">Stroutrup</a> among other texts), but it still takes me a lot of effort to decide which mechanism is best for a given scenario - and this is where a portfolio of memory-related design patterns would be useful.</p>
  
  <p>For example, yesterday I had to create a class <code>Results</code>, that was a container for a few objects and a collection (std::vector in this case) of yet another type of objects. So there are a few design questions I couldn't really answer:</p>
  
  <ol>
  <li>Should I return this class by value, or by smart pointer?</li>
  <li>Inside the class, should the vector and the objects be normal members, or should they be stored as smart pointers again?</li>
  <li>In the vector, should I store the objects directly, or smart pointers to them again?</li>
  <li>What should the getters defined on my Results class return (i.e. values, references or smart pointers)?</li>
  </ol>
  
  <p>Of course, smart pointers are cool and what not, but they create syntactic clutter and I am not convinced if using malloc for every single object is optimal approach.</p>
  
  <p>I would be grateful for answers for the specific points above, but even more for some longer and more general texts on memory-related design patterns - so that I can solve the problems I will have on Mondays as well!</p>