Go Back   Velocity Reviews > Newsgroups > C++
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

C++ - A question about allocating resources

 
Thread Tools Search this Thread
Old 04-04-2005, 09:02 AM   #1
Default A question about allocating resources


Hello experts!!

I reading in a book about C++ and there is something that I'm not sure
about. I don't belive that the book is wrong but
I will just ask you out there what you think.

The book says the following "Note that you cannot assume that all resources
are automatically released when the
entire program tetminates. While this is true for resources allocated
exclusively for
this program, such as internal memory, there are other resources obtained
from the
operating system, such as file locks or ports, that must be explicitly
released when the program terminates."

My question I thought that when a program terminates all resources no matter
if it's file lock, ports, memory or something else) is released
automatically when the program terminate. Is the book right or wrong?

Many thanks!

//Tony




Tony Johansson
  Reply With Quote
Old 04-04-2005, 10:47 AM   #2
Ivan Vecerina
 
Posts: n/a
Default Re: A question about allocating resources
"Tony Johansson" <> wrote in message
news:qw64e.21207$...
: I reading in a book about C++ and there is something that I'm not sure
: about. I don't belive that the book is wrong but
: I will just ask you out there what you think.
:
: The book says the following "Note that you cannot assume that all
resources
: are automatically released when the
: entire program tetminates. While this is true for resources allocated
: exclusively for
: this program, such as internal memory, there are other resources obtained
: from the
: operating system, such as file locks or ports, that must be explicitly
: released when the program terminates."
:
: My question I thought that when a program terminates all resources no
matter
: if it's file lock, ports, memory or something else) is released
: automatically when the program terminate. Is the book right or wrong?

This is platform-specific, and not really a C++ question.

Most modern operating systems (Unices and the WinNT derivatives) reliably
dispose of all or most resources allocated by a client process that
has terminated. Windows versions up to Win98/Me were more likely to
display such a problem.

In any case, because you never know if your class/module will be used
as part of a larger application, a professional programmer will
always make sure that all resources acquired by a module are released.


Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com




Ivan Vecerina
  Reply With Quote
Old 04-04-2005, 11:44 AM   #3
Jeremiah L.Jiang
 
Posts: n/a
Default Re: A question about allocating resources
Some resources will not be released if you don't release them
explicitly. And other applications will never use them. For example,
when you manipulate a scanner, you must open Data Source before you can
use it. But you must close Date Source after you finish scanning.
Otherwise, other applications can't use the scanner.



Jeremiah L.Jiang
  Reply With Quote
Old 04-05-2005, 03:49 AM   #4
Jack Klein
 
Posts: n/a
Default Re: A question about allocating resources
On Mon, 04 Apr 2005 08:02:30 GMT, "Tony Johansson"
<> wrote in comp.lang.c++:

> Hello experts!!
>
> I reading in a book about C++ and there is something that I'm not sure
> about. I don't belive that the book is wrong but
> I will just ask you out there what you think.
>
> The book says the following "Note that you cannot assume that all resources
> are automatically released when the
> entire program tetminates. While this is true for resources allocated
> exclusively for
> this program, such as internal memory, there are other resources obtained
> from the
> operating system, such as file locks or ports, that must be explicitly
> released when the program terminates."
>
> My question I thought that when a program terminates all resources no matter
> if it's file lock, ports, memory or something else) is released
> automatically when the program terminate. Is the book right or wrong?
>
> Many thanks!
>
> //Tony


As others have said, some systems clean up better than others,
although there might always be some types of resources on any system
that might not be released until the next reboot or some such.

But you need to understand that this is not really a C++ language
question. The C++ language standard can only place requirements on
the actions of a correct conforming C++ program while it is executing.
It has no authority over your computer's operating system, and it
cannot in any way specify what your operating system does before or
after it runs a C++ program.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


Jack Klein
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use resources in jar daniele Software 0 10-17-2007 02:46 PM
Re: Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good God DVD Video 3 04-25-2005 04:19 PM
Re: Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good Filthy Mcnasty DVD Video 0 04-25-2005 04:29 AM
Re: Safe Mode Question (A+ question) Gordon Findlay A+ Certification 0 06-16-2004 10:48 AM
Legacy Devices and Reserving Resources Question Bloke_in_a_box A+ Certification 1 05-04-2004 06:52 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46