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

Re: Sv: Memory allocators

Peter Burns wrote:
>>>(BTW - how do you handle out-of-memory situations?)
>>Well, doesn't new throw an exception if it fails? I'm not catching any
>>exceptions from new, so I handle out-of-memory exactly like new does.
>I wouldn't really on new throwing an exception  unless you have explicitly

s/really/rely/ ?

>set the new handler to do this. I think that most implementations of new
>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 :(


Drive A: not responding...Formatting C: instead