Variable-length stack allocated arrays

grauzone none at example.net
Mon Jan 11 02:27:40 PST 2010


Andrei Alexandrescu wrote:
> grauzone wrote:
>> Andrei Alexandrescu wrote:
>>> grauzone wrote:
>>>> bearophile wrote:
>>>>> void bar(int n) {
>>>>>   scope int[] a = new int[n]; // stack-allocated
>>>>>   foo(a);
>>>>> }
>>>>
>>>> Why are you making such proposals, when one of the core developers 
>>>> even thought about removing normal "scope"? It's almost 100% 
>>>> guaranteed that nobody will listen.
>>>>
>>>> I personally find it a good idea to find new ways to reduce 
>>>> producing memory garbage. The D GC is slow and bad, so you'd better 
>>>> avoid it.
>>>>
>>>> Let's make this claim: it is impossible to write high performance 
>>>> applications (that need to make use of dynamic memory allocation) in 
>>>> D without resorting to "unsafe" techniques. That would include 
>>>> allocating memory on the stack, or manually freeing memory.
>>>
>>> I write high-performance code in D without resorting to unsafe 
>>> techniques. Much of my code allocates arrays only in the beginning 
>>> and uses them throughout.
>>
>> I intended to exclude this case with applications "that need to make 
>> use of dynamic memory allocation". But I guess this doesn't apply to 
>> programs that only allocate on initialization.
>>
>> So, how about programs that allocate/release memory while doing 
>> computations?
> 
> "Oil is found in the minds of men."

Can you explain what this means in the context of the problem mentioned 
above?

> Andrei



More information about the Digitalmars-d mailing list