Memory allocation purity

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Wed May 14 16:35:56 PDT 2014


On Wed, 14 May 2014 22:42:46 +0000
Brian Schott via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> What is the plan for the "pure"-ity of memory management?
>
> Right now the "new" operator is considered to be pure even though
> it is not, but related functinos like malloc, GC.addRange,
> GC.removeRange, and others are not.
>
> This prevents large portions of std.allocator from being pure.
> This then prevents any containers library built on std.allocator
> from being pure, which does the same for any funcions and data
> structures written using those containers.
>
> If malloc can never be considered pure, even when hidden behind
> an allocator, why can it be considered pure when hidden behind
> the GC?

I think malloc should definitely be considered pure for the same reasons that
new is considered pure. I don't know about the other memory management
functions though. I'd really have to think through their side effects to have
an opinion on them. If we can make them pure though, that would certainly help
with ensuring that allocators can be pure.

- Jonathan M Davis


More information about the Digitalmars-d mailing list