473,396 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
Jul 23 '05 #1
3 1378
"Tony Johansson" <jo*****************@telia.com> wrote in message
news:qw*******************@newsb.telia.net...
: 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
Jul 23 '05 #2
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.

Jul 23 '05 #3
On Mon, 04 Apr 2005 08:02:30 GMT, "Tony Johansson"
<jo*****************@telia.com> 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
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Crirus | last post by:
What do you think about this approaches, wich one is the best? For x As Integer = u.GetViewBounds.X To u.GetViewBounds.X + u.GetViewBounds.Width For y As Integer = u.GetViewBounds.Y To...
4
by: Tony Johansson | last post by:
Hello! Assume we have the following classes and interfaces. We have a class called Inventory that is associated to a class called Product. We have some classes that is derived from this...
9
by: Gustaf | last post by:
I'm confused about structured error handling. The following piece of code is a simplification of a class library I'm working on. It works, and it does what I want, but I'm still not convinced that...
15
by: cedgington | last post by:
I wanted to take advantage of the large set of functionality offered by the framework, so for my latest project I'm using managed C++ with .NET v2. I'm using the gcnew operator in two different...
19
by: allanallansson | last post by:
Hi i would like some guidelines for a experiment of mine. I want to experiment with the swap and ctrl-z in linux. And for this i want to create a c program that allocates almost all the free memory...
15
by: sethukr | last post by:
Hi everybody, While running the following program in GCC, i'm very much screwed. main() { char *ptr1; char arr; int i; char *ptr2;
3
by: Kane | last post by:
When you create node 1 you allocate memory and link it Again when you create node 2 you would allocate memory for that node in a different section of the code. Is there more efficient way where I...
27
by: matt | last post by:
Hello group, I'm trying to become familiar with the information hiding design rules, and I have a lot (3) of questions for all you experts. AFAIK, a generic module has 2 files: ...
19
by: =?ISO-8859-1?Q?Nordl=F6w?= | last post by:
I am currently designing a synchronized queue used to communicate between threads. Is the code given below a good solution? Am I using mutex lock/unlock more than needed? Are there any resources...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.