[zeromq-dev] Memory allocation/Exception
Negm, Ayman
Ayman.Negm at dermalog.com
Tue Mar 24 10:19:59 CET 2009
Hello,
we are planing to use ZeroMQ since our performance tests runs fine so far, but we noticed that you allocate
memory using 'new' and then make assert check, which will not be evaluated in case of std::bad_alloc.
<example>
libzmq ver0.5: dispatcher.cpp
lines: 34/35
pipes = new command_pipe_t [thread_count * thread_count];
assert (pipes); // will not be arrived in case of std::bad_alloc
</example>
Since I don't see in your code that you overwrite the new operator, so modern compiler will throw std::bad_alloc
<C++ISO_standard>
3.7.3 Dynamic storage duration
========================
The following allocation and deallocation functions
(18.4) are implicitly declared in global scope in each translation unit of a program
void* operator new(std::size_t) throw(std::bad_alloc);
void* operator new[](std::size_t) throw(std::bad_alloc);
void operator delete(void*) throw();
void operator delete[](void*) throw();
</C++ISO_standard>
Even if the compiler does not throw bad_alloc and initialize the pointer with NULL, in This case I would expect to
do something else (e.g. set another error handler function for such failure) than crashing the whole application.
Because the user of your API may want to wait until the system have enough memory and retry again.
I just want to understand why you have selected the assertion way?
Thank you in advance for your answer,
Ayman
________________________________
DERMALOG Identification Systems GmbH * Mittelweg 120, 20148 Hamburg * www.dermalog.com
Company Registration: Amtsgericht Hamburg, HRB 69547 * Gesch?ftsf?hrer/CEO: G?nther Mull
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20090324/c2b28dcd/attachment.htm>
More information about the zeromq-dev
mailing list