![]() |
|
|
|||||||
![]() |
C++ - A question about allocating resources |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
"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 |
|
|
|
#3 |
|
Posts: n/a
|
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 |
|
|
|
#4 |
|
Posts: n/a
|
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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |