Initializing a fixed sized array
Jonathan M Davis
jmdavisProg at gmx.com
Fri May 31 23:28:30 PDT 2013
On Saturday, June 01, 2013 08:16:47 finalpatch wrote:
> This form is nice:
>
> int[3] x = [1,2,3];
>
> But it is horribly inefficient because it
>
> 1. allocates a dynamic array from the GC
> 2. writes 1,2,3 to the dynamic array
> 3. copies the 1,2,3 back to the static array
Are you sure that that still allocates? I thought that that had been fixed. If
it hasn't, it will be. The issue is completely temporary and not intended to
be the case long term.
Now, assuming that you're right and that still allocates, it's trivial to
create a variadic function to initialize it for you by essentially generating
int[3] x;
x[0] = 1;
x[1] = 2;
x[2] = 3;
for you. So, it's easy enough to get around, but the problem should either
already be fixed in the compiler, or if not, it will be at some point in the
near future.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list