Re: Handling Out Of Memory
From: Bruce Roberts (ber_at_bounceitattcanada.xnet)
Date: 03/31/04
- Next message: NeWuSeR: "Not really Delphi"
- Previous message: Bruce Roberts: "Re: Safe pointer arithmetic and typecasts :D"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: NeWuSeR: "Not really Delphi"
- Previous message: Bruce Roberts: "Re: Safe pointer arithmetic and typecasts :D"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|