JKop wrote:
Is there anything inherently "efficent" or "...bad" about using dynamic
memory allocation... ?
Putting objects on the "stack" (automatic storage) is more typically
efficient since all of the work needed to allocate and deallocate memory
for the object can be done during compile time. The downside is that
there is no standard way to see if you running out of stack space.
With dynamically allocated memory (free store) work needs to be done
during runtime, which means slower code. Depending on the compiler,
run-time library and platform the performance difference can be quite
significant. With dynamic memory allocation there is also the risk of
heap fragmentation. This is a concern when a system has to run 24/7 and
frequently allocates and deallocates memory. This can fragment the heap
in such away that there is no free memory block large enough to fulfill
an allocation request even though the total amount of free memory is
sufficient. Another disadvantage of dynamically allocated objects is
that you have to explicitly deallocate too, unless you use smart
pointers. Without smart pointers it is very hard to write exception safe
leak free code.
--
Peter van Merkerk
peter.van.merkerk(at)dse.nl