Should GC.malloc be considered 'pure'?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Jun 9 13:08:33 PDT 2011


On 6/9/11 12:51 PM, KennyTM~ wrote:
> Given that the 'new' expression can be used in 'pure', should it be that
> GC allocation functions like GC.malloc, GC.qalloc and GC.extend (?) be
> weakly pure also? And should it apply to other managed allocators as
> well, e.g. the proposed TempAlloc?
>
> I'm asking this as one of the specializations of std.conv.toImpl calls
> GC.malloc, which is one of the 11 causes preventing std.conv.to from
> being pure, and GC.qalloc and GC.extend (and memcpy and Array.capacity)
> are used by std.array.appender (of pure range), and appender is also a
> major reason why std.conv.to is not pure.

GC.malloc is not technically pure because its result does not only 
depend on arguments - it's a fresh value each time. So the compiler 
can't apply pure reasoning to it.

Andrei


More information about the Digitalmars-d mailing list