Memory allocation purity

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sat May 17 12:14:09 PDT 2014


On Thu, 15 May 2014 11:03:13 -0700
Walter Bright via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> On 5/15/2014 2:45 AM, Don wrote:
> > An interesting side-effect of the recent addition of @nogc to the
> > language, is that we get this ability back.
>
> I hadn't thought of that. Pretty cool!

Definitely, but we also need to be careful with it. If @nogc just restricts
allocations by the GC and not allocations in general, and if we make it so
that malloc is pure (even if it's only when wrapped by a function which throws
an Error when malloc returns null), then I don't think that we quite get it
back, because while the GC may not have allocated any objects, malloc could
still have be used to allocate them. We'd need to be able to either say that
_nothing_ allocated within the function, which isn't quite what @nogc does as
I understand it (though admittedly, I haven't paid much attention to the
discussions on it, much as I would have liked to). So, maybe we need to
find a way to make it so that a wrapped malloc can be pure but isn't
@nogc? Though if we go that route, that implies that @nogc should have
been @noalloc. Regardless, I think that making malloc pure
definitely affects the issue of whether a @nogc function can be assumed
to not return newly allocated memory.

- Jonathan M Davis


More information about the Digitalmars-d mailing list