[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sv: Sv: Memory allocators



>>set the new handler to do this. I think that most implementations of new
>>just
>>return NULL if memory allocation failed. At least this is what happens
with
>>visual c++.
>
>Ouch. According to the standard it has to throw bad_alloc. And AFAIK for
>g++ it does exactly that. So we have to do one of these:
>(1) Let autoconf check which behavior we have and define some macro for
>appropriately checking for allocation failure
>(2) Always both catch bad_alloc and check the return value of new
>(3) Override operator new with a custom one returning 0 on failure
>
>I don't like any of these possibilities :(
>
Actually, I like throwing an exception better than returning 0, partly
because its really, really, really a pain to have to check the return value
of new all the time, partly because running out of memory is pretty fatal to
the proper functioning of many or even most functions, so you don't want to
catch the exception anyway. This is what I see as getting both utility and
functionality "for free".

Nomatter what is decided, getting everything to function uniformly is not
harder than calling _set_new_handler() with our own handler that does what
we want it to do.

Another good reason for throwing an exception is that if that's what new is
supposed to do, then that's what applications will expect. I think it should
be a compiler option wheter or not to have PPlay install its own new
handler, and I think the behavior should be on by default.