
23 Dec
2005
23 Dec
'05
9:22 a.m.
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