pure and custom new / delete

Timon Gehr timon.gehr at gmx.ch
Tue Jun 26 09:44:41 PDT 2012


On 06/26/2012 06:05 PM, Benjamin Thaut wrote:
> Am 26.06.2012 18:02, schrieb Timon Gehr:
>> On 06/26/2012 05:59 PM, Benjamin Thaut wrote:
>>> As delete and new / delete overloading is deprecated and it was
>>> recommeneded to write tempaltes to repalce these expressions I did so.
>>>
>>> But now as everything starts to work out pretty nice I've walked into
>>> the 'purity' issue. Pure functions are only allowed to call other pure
>>> functions and as far as I know there is no way to make functions
>>> "trusted pure". But I would need to make certain functions "trused
>>> pure", espeically my new and delete replacements. Any suggestions how to
>>> do this?
>>>
>>> Kind Regards
>>> Benjamin Thaut
>>
>> You can cast function pointers to pure, or mark extern(C) memory
>> allocation functions as pure.
>
> extern(c) is not an options as there is a structure of various different
> allocators that implement a common interface which all is written in D.
>
> Is the compiler smart enough to optimize away a function pointer I
> created localy just so I can cast it?
>
> Kind Regards
> Benjamin Thaut

You can examine the assembly code. DMD is perhaps not smart enough (it
is unable to inline directly called function literals, so I am not
optimistic.) LDC and GDC should certainly optimize it out.


More information about the Digitalmars-d mailing list