Boost logo

Boost :

From: Markus Schöpflin (markus.schoepflin_at_[hidden])
Date: 2005-12-23 04:22:26


Daryle Walker wrote:

> Shouldn't it be applied only if std::malloc returns NULL on 0-sized
> allocations? A std::malloc implementation that returns unique pointers for
> zero sizes is OK. Maybe something like:
>
> void * p = std::malloc( n );
> if ( !n && !p ) p = std::malloc( 1 );
> return p;
>
> would be better?

As far as I can tell, memory allocators usually allocate some smallest
possible quantity (say 8 or 16 bytes), no matter how small the size is.
This happens even on zero sized reuqests, when the allocator returns a non
zero pointer.

So my proposed fix just does what the allocator does anyway. I don't think
we need the extra complication. Besides, zero sized requests are probably
rare anyway.

Markus


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk