the reason new never returns a null pointer is because it throws an exception if it can't allocate the requested amount of memory.
Unless you disable exceptions in your specific compiler, then new can of course return null pointers (depending on implementation specifics).
To expand on this, new
can be made to return NULL
upon failure if you use nothrow
. In which case, new
may return NULL
. If there isn't any available memory when you request it, there probably won't be any the next time you request it 700 nanoseconds later, and there isn't much sense in getting stuck in a potentially infinite loop.
I'm curious as to why you're using malloc
instead of new
has a point about consistency not being critical to having a working product, I will say that I would be horribly frustrated if a project was inconsistent in its conventions.
This line (from MarshallingFunctions.hh):
(boolRep != 0) ? bl = true : bl = false;
is technically valid, but it goes against every normal use of the ternary operator. If you wanted it to be consistent with how the other 99.99% of the world programs, it would be:
bl = boolRep != 0;
or at most:
bl = (boolRep != 0) ? true : false;
If you really wanted to do it that way though, you could also do
if (boolRep != 0) b1 = true; else b1 = false;
which is slightly common (but depends on your coding conventions), but I'd say by far the most common are the first two I mentioned.
I will commend you on seeking to improve your code. It's not always easy to ask for a critical review.
Edited by Cornstalks, 01 May 2012 - 12:02 AM.