I continue to see "resource" on the contrary to "dynamic memory" from C++ Primer 5th:
By default, a pointer used to initialize a smart pointer must point to dynamic memory because, by default, smart pointers use
delete
to free the associated object. We can bind smart pointers to pointers to other kinds of resources. However, to do so, we must supply our own operation to use in place ofdelete
.
If you use a smart pointer to manage a resource other than memory allocated by
new
, remember to pass a deleter.
What are the resources mentioned here?
And is it indicating that :
There is(are) other way(s) to allocate dynamic memory compared to using new
. ( Aren't all dynamic memory essentially allocated by using new
?)
Update:
The reason why I am unclear about the quoted text is that I was thinking wrong about something, which it's that I had been thinking of smart pointer is only invented for/related to dynamic memory management. So the example uses smart pointer to manage a non-dynamic memory stuff makes me confused.
A good explanation from a senior:
The smart pointer doesn't care at all about something being dynamic memory as such. It's just a way to keep track of something while you need it, and destroy that something when it goes out of scope. The point of mentioning file handles, network connections, etc., was to point out that they're not dynamic memory, but a smart pointer can manage them just fine anyway.