Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > When to use a garbage collector?

Reply
Thread Tools

When to use a garbage collector?

 
 
Carlo Milanesi
Guest
Posts: n/a
 
      06-13-2008
Krice ha scritto:
> Yannick Tremblay kirjoitti:
>> message: "Memory full, please close some other applications". Do you
>> think this is a bad idea and that it would be better for the mobile to
>> shutdown and turn itself off?

>
> All these examples where memory recovery is needed seem to be
> anything else than normal application running in PC, so I guess
> it's good to have exceptions when they have some kind of real
> function, but I think it's a waste of time to write such code in
> PC application, because the construction never(?) fails, unless
> you run out of memory.


What do you mean with "some kind of real function"?

Even in PC applications exceptions are very useful.
Try to create a 99999x99999 color bitmap using Windows Paint
(mspaint.exe) and you will get an error message, but the application
will continue to run. Would you prefer a crash?

--
Carlo Milanesi
http://digilander.libero.it/carlmila
 
Reply With Quote
 
 
 
 
Jerry Coffin
Guest
Posts: n/a
 
      06-14-2008
In article <e1dc93ef-99f4-4754-ae48-
http://www.velocityreviews.com/forums/(E-Mail Removed)>, (E-Mail Removed) says...
> Yannick Tremblay kirjoitti:
> > message: "Memory full, please close some other applications". Do you
> > think this is a bad idea and that it would be better for the mobile to
> > shutdown and turn itself off?

>
> All these examples where memory recovery is needed seem to be
> anything else than normal application running in PC, so I guess
> it's good to have exceptions when they have some kind of real
> function, but I think it's a waste of time to write such code in
> PC application, because the construction never(?) fails, unless
> you run out of memory.


Construction can fail for _lots_ of reasons other than running out of
memory. In networking, for example, you might have an object to
represent a connection to a server. If you can't connect to the server,
you can't create the connection object. OTOH, that hardly implies that
the program must fail -- you might easily have a number of servers to
try, and as long as you can connect to any one of them, your program can
continue to run perfectly well.

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
 
 
 
Richard Herring
Guest
Posts: n/a
 
      06-23-2008
In message <(E-Mail Removed)-berlin.de>, Stefan Ram
<(E-Mail Removed)-berlin.de> writes
>Jerry Coffin <(E-Mail Removed)> writes:
>>Oh my. In most cases you can do something reasonably productive when an
>>exception gets thrown. Even in the worst case, you probably want to
>>catch it and print out the most meaningful error message you can

>
> A function should not be coupled to an application more than
> necessary, so that the function might be used in a library as well
> (or one might even write functions for use in a library).
>
> Usually, a function does not know which user interface the
> program calling it employs. ›::std::cout‹ might be associated
> with a console, or it might not be, when the application is GUI
> based, web based or a driver or a service without a user interface.
>
> So what should ›print out‹ mean in the general case?
> Should the function use ›::std::cout << ...‹ or what else to
> ›print out‹ the most meaningful error message it can?
>


It should delegate that decision to your chosen logging package.

--
Richard Herring
 
Reply With Quote
 
Matthias Buelow
Guest
Posts: n/a
 
      06-25-2008
Carlo Milanesi wrote:

> Even in PC applications exceptions are very useful.
> Try to create a 99999x99999 color bitmap using Windows Paint
> (mspaint.exe) and you will get an error message, but the application
> will continue to run. Would you prefer a crash?


Guarding against invalid user input is not a good use case for
exceptions. Erroneous user input is hardly exceptional, is it?

 
Reply With Quote
 
Noah Roberts
Guest
Posts: n/a
 
      06-25-2008
Matthias Buelow wrote:
> Carlo Milanesi wrote:
>
>> Even in PC applications exceptions are very useful.
>> Try to create a 99999x99999 color bitmap using Windows Paint
>> (mspaint.exe) and you will get an error message, but the application
>> will continue to run. Would you prefer a crash?

>
> Guarding against invalid user input is not a good use case for
> exceptions. Erroneous user input is hardly exceptional, is it?
>


Depends on the situation really. The input that the user has entered in
this case is actually valid, in that it is a real size, but the error is
more likely caused by inability to allocate the necessary memory for
such a huge bitmap.

I'd call that exceptional even if it is ultimately caused by a stupid user.
 
Reply With Quote
 
Carlo Milanesi
Guest
Posts: n/a
 
      06-25-2008
Matthias Buelow ha scritto:
> Carlo Milanesi wrote:
>
>> Even in PC applications exceptions are very useful.
>> Try to create a 99999x99999 color bitmap using Windows Paint
>> (mspaint.exe) and you will get an error message, but the application
>> will continue to run. Would you prefer a crash?

>
> Guarding against invalid user input is not a good use case for
> exceptions. Erroneous user input is hardly exceptional, is it?


It not an invalid input. In this program you can specify a width from 1
to 99999 pixels and a height from 1 to 99999 pixels.
For example, I can create a 10x99999 bitmap or a 99999x10 bitmap.
This program appears to allocate about 6 to 10 bytes for every pixel.
Perhaps, if your computer can allocate 60 GB of virtual memory for a
single process you can create such a bitmap.
It would be silly to limit the memory of the bitmap, as different users
may have different memory.
I think that raising an exception is the best way to handle this kind
user input.

--
Carlo Milanesi
http://digilander.libero.it/carlmila
 
Reply With Quote
 
Alisha
Guest
Posts: n/a
 
      06-26-2008
On Jun 12, 12:38*am, Walter Bright <(E-Mail Removed)>
wrote:
> Carlo Milanesi wrote:
> > Hello,
> > * * traditionally, in C++, dynamically allocated memory has been managed
> > explicitly by calling "delete" in the application code.

>
> > Now, in addition to the standard library strings, containers, and
> > auto_ptrs, gurus suggest that may be better to use a reference-counted
> > smart pointer, or a garbage-collector.

>
> > But in which cases it is better to use one technique and in which cases
> > another? IOW, which is the design criterion?

>
> For scarce resources, like resource handles and large memory blocks, use
> reference counting. For routine memory allocations, use gc.
>
> > And if, after having completed a working system, a technique would
> > result more performing than another, or better for other reasons, is it
> > advisable to change the memory management strategy of that working system?

>
> Using gc effectively entails using different coding/design techniques,
> so it is not practical to try to shift the design after the fact.
>
> -------------
> Walter Bright
> Digital Marshttp://www.digitalmars.com
> C, C++, D programming language compilers


What is the work of Garbage collector?
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Do you use a garbage collector (java vs c++ difference in "new") Arne Vajhj Java 12 04-13-2008 12:13 AM
Re: Do you use a garbage collector (java vs c++ difference in "new") Ian Collins Java 0 04-11-2008 02:41 AM
When to use Boehm-Demers-Weiser Garbage Collector? PengYu.UT@gmail.com C++ 0 03-30-2006 04:37 AM
Just Curious, What Kind Of Garbage Collector Does Sun's JVM Use? res7cxbi@verizon.net Java 2 01-06-2006 11:29 AM
Templates - Garbage In Garbage Not Out ramiro_b@yahoo.com C++ 1 07-25-2005 04:48 PM



Advertisments