Re: Handling Out Of Memory

From: Bruce Roberts (ber_at_bounceitattcanada.xnet)
Date: 03/31/04


Date: Wed, 31 Mar 2004 15:42:21 -0500


"Skybuck Flying" <nospam@hotmail.com> wrote in message
news:c4eor2$9tf$1@news2.tilbu1.nb.home.nl...

> Let me guess.. I could handle other exceptions ?
>
> I think not... only exception that occur between try and except are
> catched...

I don't think that you read my post carefully or perhaps I wasn't clear
enough for you.

> Except maybe when nested try except blocks are used.
>
> Please explain why you think that if you care to do so.

As I recall your example consisted of something like

    try
        // something
    except
        end;

In this form all exceptions generated while the program is executing between
the try and except are unconditionally trapped and ignored. As I said
before, not a very good idea.

> Currently I am not using any trees... I am using lists and with lists it's
> possible to prevent exceptions :D

Lists are nothing more than degenerate trees. There may be particular
exceptions that your lists can recover from although I'm sceptical. Consider
the out of memory condition. Must the code using your list always write

    if not someList.Add (something)
    then // some how cope with the fact that something can't be added

Instead of simply

    someList.Add (something);

After all, what is the using code going to do? And if the using code really
is able to cope with an out of memory condition isn't

    try
        someList.Add (something);
    except
        on eOutOfMemory do // cope
        end;

just as clear to the reader.

> > So write it such that it tests for available memory before attempting to
> > allocate it.
>
> There is no point in doing that... one can try to call the getmem function
> if it s true ok
> if not handle it ;)

Handle it how? Its not reasonable to expect that the code that allocates a
node in a list should know how to handle a situation in which the node
cannot be allocated. That is the responsibility of the code that is using
the list. After all the using code might have to terminate its job. OTH it
might be able to adjust some parameters and keep on trucking. Either way the
allocation code should be ignorant of the situation. If it isn't, it becomes
dependant on the calling code and that, as we all know, is bad programming.
It removes any possibility of code reuse from the low level code and
introduces maintenance complications.

> By the time one does the actual allocation... the get heap status might
have
> changed as well.
> So checking if enough mem is available before hand is probably not the
right
> way to do it.

You'd be right if the check was for the exact amount required. I would
suggest, however, that one simply needs to check that a reasonable amount of
memory was available. As I said before, by the time one gets an out of
memory exception its generally too late to do anything about it.



Relevant Pages

  • Re: Quantum Gravity 23 (abbreviated from Quantum Gravity...): Baez vs Doctorow
    ... lists and/or similar types of exclusionary lists, ... physics and mathematics - almost an encyclopedic amount (present ... though there may be other exceptions) together with most USA ... extremely stressful lives in which they abandon Conformity. ...
    (sci.physics)
  • Re: Capitalizing 1st letter of sentence
    ... My auto-correct's EXCEPTIONS ... lists are full up to the neck with a list of words. ... > simply getting a lot of non-capitalized sentences. ... I did just upgrade to SP2, but this problem is something I ...
    (microsoft.public.word.spelling.grammar)
  • Re: ADO.NET Not Returning Error
    ... I checked the docs and SqlCommand.ExecuteNonQuery lists SqlException as a ... SqlDataReader.Read nor IDataReader.Read list any exceptions that can be ... dealt with either came back through a SqlException on the execute or as ... >> Ashton Hobbs ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Allocatable Components of Derived Type
    ... One exception I guess is an allocatable array declared in a subroutine ... There are *NO* exceptions. ... Such a case will not cause a memory leak, ... If you try to allocate the array again without ...
    (comp.lang.fortran)
  • Re: Allocatable Components of Derived Type
    ... One exception I guess is an allocatable array declared in a subroutine ... Such a case will not cause a memory leak, ... If you try to allocate the array again without ... exceptions, I'd suggest turning in a defect report to the standard ...
    (comp.lang.fortran)