Stephen C. Steel wrote:
>> I have seen that in sipxtapi, sometimes we check for new failure with an
>> if, sometimes we don't.
>>
>> Standard behaviour is that if it runs out of memory, it throws
>> std::bad_alloc. This holds for visual studio and gcc 2.95
>> (http://www.gnu.org/software/gcc/gcc-2.95/c++features.html - * operator
>> new now throws bad_alloc where appropriate.), but for WinCE, it returns 0.
>>
>> Checking with an if after each allocation and using delete can produce
>> very complicated code.
> 
> In older versions of the Microsoft C++ libraries, new would also return 0
> when
> out of memory (instead of throwing std::bad_alloc like newer versions do).
> However, there is a _set_new_handler() function that allows you to register
> a function to be invoked whenever allocation fails.
> 
> I believe WinCE also supports _set_new_handler(), so this might be a much
> cleaner
> Solution.
> 
> Stephen C. Steel
> 

I know about _set_new_handler, it's microsoft extension. In ANSI C++
there is set_new_handler. We could install custom handler in sipxportlib
(in constructor of a static singleton for this purpose), but user could
also set his own handler, in which case our handler wouldnt be called,
as only 1 handler is called.

Jaroslav Libak
_______________________________________________
sipxtapi-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipxtapi-dev/

Reply via email to