Summary
Dynamic memory management gives you the tools to start working directly with memory yourself, freeing you from the confines of the stack. In this chapter we have seen how to allocate and free memory, and the challenges of having to do this manually.
We have also looked at generics, and used these to allow us to create reusable dynamic arrays and linked lists. Generics allow us to use variable types in our code, and are achieved using templates in C++. When we use the template we say what type to use in place of the variable type, and the template is then created with that type for us.
Lastly, we have used GitHub Copilot to help us write utility code for a dynamic array and a linked list. These are common programming exercises, so Copilot has had lots of exposure to them. Hopefully the experience of using this showed you that they are both a useful tool, but also a tool with many limitations.
In the next chapter we will see some convenient ways of enhancing out utility structs by embedding functions within the structs alongside the data. This will make it easier to work with our dynamic array and should give you some cool new tools to work with.