C++ new and delete
Posted Apr 7, 2008 0:49 UTC (Mon) by
pr1268 (subscriber, #24648)
In reply to:
Making up falsehoods by jchrist
Parent article:
Striking gold in binutils
how do you dynamically allocate/deallocate memory?
A big push for "modern" C++ programming is to use the standard library's container classes, e.g., vector, list, deque, etc. instead of arrays created with new and delete.
The primary rationale for using dynamically-allocated memory in the first place is to defer until execution time reserving only as much space as is needed (since memory is a scarce resource). The C++ containers have a rich set of methods which allow array-like operation while managing the dynamic allocation (and subsequent releasing) of resources at the library level (instead of making the programmer do it him/herself with new and delete).
I can't speak for why virtual methods are seldom described in literature, but my intuitive perception is that they're this philosophical concept in computer science (object-oriented programming in particular) whose existence programmers are expected to know but avoid using unless no other practical solution exists--kind of like recursion.
(
Log in to post comments)