April 27, 2013
On 04/27/2013 07:29 AM, Steven Schveighoffer wrote:
> On Fri, 26 Apr 2013 07:58:34 -0700, Luís Marques <luismarques@gmail.com>
> wrote:
>
>> Should this be supported?
>>
>>      double[8] foo = [1.0, 2.0, void, 3.0, 3.5, void, void, void];
>>
>> (it's not supported at the moment)
>
> Have you considered what this does?  Consider a standard [1.0, 2.0] call:
>
> In essence, it pushes 1.0 and 2.0 onto the stack, then calls a function
> to allocate the memory and use the given data.
>
> What will end up happening is the data is copied from the stack to the
> heap.  It's just in your case, the data copied is garbage.  I see little
> point in supporting this.
>
> -Steve

(This is a DMD performance bug.)
April 27, 2013
On Saturday, 27 April 2013 at 05:29:41 UTC, Steven Schveighoffer wrote:
> On Fri, 26 Apr 2013 07:58:34 -0700, Luís Marques <luismarques@gmail.com> wrote:
>
>> Should this be supported?
>>
>>     double[8] foo = [1.0, 2.0, void, 3.0, 3.5, void, void, void];
>>
>> (it's not supported at the moment)
>
> Have you considered what this does?  Consider a standard [1.0, 2.0] call:
>
> In essence, it pushes 1.0 and 2.0 onto the stack, then calls a function to allocate the memory and use the given data.
>
> What will end up happening is the data is copied from the stack to the heap.  It's just in your case, the data copied is garbage.  I see little point in supporting this.
>
> -Steve

That is an implementation detail.
April 28, 2013
On Sat, 27 Apr 2013 06:43:58 -0700, deadalnix <deadalnix@gmail.com> wrote:

> On Saturday, 27 April 2013 at 05:29:41 UTC, Steven Schveighoffer wrote:
>> On Fri, 26 Apr 2013 07:58:34 -0700, Luís Marques <luismarques@gmail.com> wrote:
>>
>>> Should this be supported?
>>>
>>>     double[8] foo = [1.0, 2.0, void, 3.0, 3.5, void, void, void];
>>>
>>> (it's not supported at the moment)
>>
>> Have you considered what this does?  Consider a standard [1.0, 2.0] call:
>>
>> In essence, it pushes 1.0 and 2.0 onto the stack, then calls a function to allocate the memory and use the given data.
>>
>> What will end up happening is the data is copied from the stack to the heap.  It's just in your case, the data copied is garbage.  I see little point in supporting this.
>>
>> -Steve
>
> That is an implementation detail.

Oh, I didn't notice that foo was a fixed-sized array, I thought the focus was on the array literal.

It does make sense that this should be possible.

-Steve
May 17, 2013
On 27/04/2013 06:29, Steven Schveighoffer wrote:
<snip>
> Have you considered what this does?  Consider a standard [1.0, 2.0] call:
>
> In essence, it pushes 1.0 and 2.0 onto the stack, then calls a function
> to allocate the memory and use the given data.
<snip>

Does it?  I would have thought it stores the numbers in the static data segment, and uses a block memory copy in order to use it to initialise a static array.

This would explain why initialising individual elements as void isn't supported.  The point of initialising as void is to eliminate the overhead of initialising when you're just going to populate the array programmatically anyway.  But with a block memory copy you can't skip over individual elements, so would have to initialise it bit by bit, which defeats the point since void is supposed to eliminate overhead, not create more.

Stewart.

-- 
My email address is valid but not my primary mailbox and not checked regularly.  Please keep replies on the 'group where everybody may benefit.
May 17, 2013
On Fri, 17 May 2013 02:46:31 -0400, Stewart Gordon <smjg_1998@yahoo.com> wrote:

> On 27/04/2013 06:29, Steven Schveighoffer wrote:
> <snip>
>> Have you considered what this does?  Consider a standard [1.0, 2.0] call:
>>
>> In essence, it pushes 1.0 and 2.0 onto the stack, then calls a function
>> to allocate the memory and use the given data.
> <snip>
>
> Does it?  I would have thought it stores the numbers in the static data segment, and uses a block memory copy in order to use it to initialise a static array.

Last time I checked, that's what it did.  But it may have changed.

As Timon and deadalnix say, it's a bug in implementation.  In any case, I was focusing only on the [] expression, not the fact that you are initializing a static array.  The static array initialization should change how the expression is handled.

-Steve
1 2
Next ›   Last »