another compiler bug?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Sat Jan 12 06:17:21 PST 2008


Aarti_pl wrote:
> Frits van Bommel pisze:
>> Aarti_pl wrote:
>>> torhu pisze:
>>>> Aarti_pl wrote:
>> [How to heap-allocate a class reference?]
>>>
>>> I managed to overcome bug in DMD with below:
>>>
>>> void func(T)() {
>>>     static TYPE res;
>>>     res = new T;
>>>         return &res;
>>> }
>>>
>>> although it will cause memory leaks for every type for which the 
>>> function is instantiated. So I consider bug in DMD as quite serious...
>>
>> That will only allocate one reference per type (*not* per call to the 
>> function). Try this workaround instead:
> 
> That's exactly what I said :-)

No, you say it will allocate a reference per instantiation and refer to 
this as a memory leak (presumably because they're not gc-ed after 
they're no longer in use).
My point was that a second call to the function (for the same type) will 
overwrite the location returned from the first call.


More information about the Digitalmars-d-learn mailing list