Memory allocation purity

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Thu May 15 08:37:37 PDT 2014


On 5/15/14, 6:02 AM, Steven Schveighoffer wrote:
> On Wed, 14 May 2014 20:50:08 -0400, Walter Bright
> <newshound2 at digitalmars.com> wrote:
>
>> On 5/14/2014 5:03 PM, Meta wrote:
>>> Allocating memory through new and malloc should always be pure, I
>>> think, because
>>> failure either returns null in malloc's case,
>>
>> malloc cannot be pure if, with the same arguments, it returns null
>> sometimes and not other times.
>
> Basically, you are saying that malloc must return the same block
> whenever it's called with the same parameters. This is simply nonsense.
>
> null is not special, it's just another block.
>
> I'm not saying malloc should be pure based on this, but the possibility
> that it returns null does not disqualify it.

Null is special - it's a singularity. It can't be subsequently used for 
constructing a proper object. That makes it different even after we 
discount for comparing pointers.

Andrei




More information about the Digitalmars-d mailing list