MISRA Discussion Forums
Rule 18-4-1 (ban of dynamic heap memory allocation) - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19)
+---- Forum: 6.18 Language support library (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=146)
+---- Thread: Rule 18-4-1 (ban of dynamic heap memory allocation) (/showthread.php?tid=586)



Rule 18-4-1 (ban of dynamic heap memory allocation) - shanz - 29-09-2008

One of the most commonly quoted advantages of object orientation is polymorphism.
C++ often relies on dynamically allocated pointers to achieve (run-time) polymorphism.

How can polymorphism be achieved without resorting to dynamic memory allocation?
I suspect that preallocating pointers on the stack is the answer but can someone please write some example code?

Thanks.


Re: Rule 18-4-1 (ban of dynamic heap memory allocation) - misra cpp - 11-10-2016

Polymorphism and the use of dynamic memory are not intrinsically linked, so polymorphism is possible without the use of dynamic memory